0

I am trying to get the following code(code pulls from cloud) into a method.

ParseQuery<ParseObject> query = ParseQuery.getQuery("Parse name");
    query.getInBackground("asdlasdKSas2", new GetCallback<ParseObject>() {
        public void done(ParseObject object, ParseException e) {
            if (e == null) {
                //Cost
                shirtCost = (TextView)findViewById(R.id.cost1);
                int s1 = object.getInt("cost");
                shirtCost.setText(s1);
                //Name
                shirt = (TextView)findViewById(R.id.snack1);
                String s2 = object.getString("item");
                shirt.setText(s2);
                //Desc
                shirtdesc = (TextView)findViewById(R.id.snack1description);
                String s3 = object.getString("description");
                shirtdesc.setText(s3);

            } else {
                // something went wrong
            }
        }
    });

shirtCost, shirt, & shirtDesc are all TextViews. I want to be able to call a function witch will replace shirt, shirtDesc, and shirtCost with what ever peramiters I put it. Here is what I tried to do (didn't work):

public void setData(String key, String classname, TextView main, TextView cost, TextView desc, <a way to put an android id in replace of the findViewByID()>){
    ParseQuery<ParseObject> query = ParseQuery.getQuery(classname);
    query.getInBackground(key, new GetCallback<ParseObject>() {
        public void done(ParseObject object, ParseException e) {
            if (e == null) {
                //Cost
                cost = (TextView)findViewById(R.id.<?>);
                int s1 = object.getInt("cost");
                cost.setText(s1);
                //Name
                main = (TextView)findViewById(R.id.snack1);
                String s2 = object.getString("item");
                main.setText(s2);
                //Desc
                desc = (TextView)findViewById(R.id. <?>);
                String s3 = object.getString("description");
                desc.setText(s3);

            } else {
                // something went wrong
            }
        }
    });
}

Any suggestions would be amazing. A solution would be even better. Hope I went into enough depth for ya'll to understand. Thanks!

So to explain. In summery, this is what I don't understand. look at this method:

public void example(TextView cost, <permeter idk how to pass. keep reading>) {
                cost = (TextView)findViewByID(HOW DO I GET THIS ID THROGUH PERIMETER??);}

I need to pass the ID through the parameter, but have absolute no idea.

4
  • What error it's exactly given to you? Commented Jun 18, 2015 at 1:22
  • Look at the last perameter. Idk how to write the perameter. @Error404 Commented Jun 18, 2015 at 1:38
  • In both codes the line 13 it's a comment. I'm not really secure about what you mean yet. Sorry. Commented Jun 18, 2015 at 1:48
  • I appreciate you trying to help and understand. It's hard to explain. Updated main post. read the new bottom portion. @Error404 Commented Jun 18, 2015 at 2:12

1 Answer 1

1

If you want to replace your values from shirtCost, shirt, and shirtdesc in your second snippet of code you have to use the same EditText that in the first one.

You said:

I want to be able to call a function witch will replace shirt, shirtDesc, and shirtCost with what ever peramiters I put it.

So you will have to use the same EditText respectively for each variable that you use in the first snippet of code. So, in your second snippet of code, your use of findViewById function have to be like this:

cost = (TextView)findViewById(R.id.cost1);
main = (TextView)findViewById(R.id.snack1);
desc = (TextView)findViewById(R.id.snack1description);

You have to use the same EditText for each variable because you want to replace it, so, indistinctly what text have you set before on your EditText, when you set again another text to them, the text that was set before are going to be replaced by the second one that you are setting.

So, if you have:

shirtCost.setText("This is an example");
shirtCost.getText(); //The value will be --> "This is an example"
shirtCost.setText("This text replace the first one");
shirtCost.getText(); //The value will be --> "This text replace the first one"

I expect it will be helpful for you!

Sign up to request clarification or add additional context in comments.

1 Comment

6.5 years later I've come to accept your answer. Thank you sir. Its people like you that grew me into a confident programmer. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.