How to retrieve data from parse?

Parse.com retrieve data method

  • 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.

  • Answer:

    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!

Cooper Scott at Stack Overflow Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.