Skip to content Skip to sidebar Skip to footer

How To Use Data Provided In A Getcallback Outside Of The Getcallback

So I'm using Parse for now to run the backend of my app. When you query your Parse database, data is returned in a seemingly weird way (to me, but I'm new to this) - qu

Solution 1:

I'm not able to test it right now, but something like this should work:

finalTableLayouttable= (TableLayout) findViewById(R.id.tableLayout);
TextView courtText;

for (inti=0; i < table.getChildCount(); i++) {
    courtText = (TextView) table.getChildAt(i).findViewById(R.id.courtText);
    finalTextViewupdateText= (TextView) table.getChildAt(i).findViewById(R.id.updateText);
    finalTextViewtimeText= (TextView) table.getChildAt(i).findViewById(R.id.timeText);

    ParseQueryquery=newParseQuery("Updates");
    query.whereEqualTo("court",courtText);
    query.orderByAscending("createdAt");
    query.getFirstInBackground(newGetCallback() {
        publicvoiddone(ParseObject object, ParseException e) {
            if (object == null) {
                Log.d("update", "The getFirst request failed.");
            } else {
                Log.d("update", "Retrieved the object.");

                Stringupdate= object.getString("update");
                Datetime= object.getCreatedAt();

                updateText.setText(update);
                java.text.DateFormatdateFormat= android.text.format.DateFormat.getDateFormat(getApplicationContext());
                timeText.setText(dateFormat.format(time));
            }
        }
    });
}

This way the only two variables from outside the inner class that need to be accessed from inside it (updateText and timeText) are declared final, so everything should work.

Solution 2:

There are two possible ways to resolve this. One, as Darshan said, is to make table final. This will allow you to access it from inside the GetCallback object (an inner class) without error. The second way is to refer back to the parent object - if this code is, for example, in an Activity subclass called DisplayTableActivity, you could put a method into it UpdateTable(String updateText, String timeText), and instead of accessing the table directly in the GetCallback object, have the following line:

DisplayTableActivity.this.UpdateTable(updateText, timeText);

That way, you can get the table's views inside that function (which belongs to the Activity) without any problems.

Post a Comment for "How To Use Data Provided In A Getcallback Outside Of The Getcallback"