i'm new to android and coding in general
i have many textviews in my app so i'm retrieving string from parse and displaying it in textview.
i'm using the following parse query
ParseQuery<ParseObject> query=ParseQuery.getQuery("Topics");
query.getInBackground("fRGt3oz8af", new GetCallback<ParseObject>(){
public void done(ParseObject arg0, ParseException arg1) {
if (arg1==null)
{
subTopicName = arg0.getString("class_1");
textView.setText("" + subTopicName);
}
else
{
Log.d("topic", "Error: " + arg1.getMessage());
}
}});
since i've many textview i have to repeat the same code for retrieve each string. so i'm trying to avoid code redundancy.
my question is how can i put the above query in different java class and call that method for retrieving each strings? or is there different method way to do it. I've never worked on parse server before so I'm really struggling with this.
Any help would be appreciated.
Try something like this:
interface ParseCallback {
void onComplete(String result);
//todo onError() ?
}
protected void parse(ParseCallback callback) {
ParseQuery<ParseObject> query = ParseQuery.getQuery("Topics");
query.getInBackground("fRGt3oz8af", new GetCallback<ParseObject>() {
public void done(ParseObject arg0, ParseException arg1) {
if (arg1 == null) {
String subTopicName = arg0.getString("class_1");
if (subTopicName != null) {
callback.onComplete(subTopicName);
}
} else {
Log.d("topic", "Error: " + arg1.getMessage());
}
}
});
}
public void example() {
parse(result -> {
runOnUiThread(() -> {
myTextView.setText(result);
});
});
}