因此,我現在使用Parse來運行我的應用程序的後端。當您查詢您解析數據庫,數據在一個看似不可思議的方式返回(給我,但我是新來的這個) -如何使用getCallback之外的getCallback提供的數據
query.getFirstInBackground(new GetCallback() {
public void done(ParseObject object, ParseException e) {
if (object == null) {
} else {
}
}
});
而且從查詢的數據可用於例如else語句中。我可以做Date time = object.getCreatedAt();獲取檢索到的對象的創建時間。
但是,問題出現了,因爲我想使用該數據來更新我的應用程序中的textView文本。我覺得數據被「卡住」在callBack中(我意識到這可能不是真實的。我試圖這樣做的方式,我得到一個錯誤:「不能引用定義的內部類中的非最終變量updateText 。在不同的方法」的錯誤是在UPDATETEXT,timeText,表,我這裏是沒有相關的代碼片段 -
TableLayout table = (TableLayout) findViewById(R.id.tableLayout);
TextView courtText;
TextView updateText;
TextView timeText;
// For each row
for (int i = 0; i < table.getChildCount(); i++) {
// Get the one `courtText` in this row
courtText = (TextView) table.getChildAt(i).findViewById(R.id.courtText);
ParseQuery query = new ParseQuery("Updates");
query.whereEqualTo("court",courtText);
query.orderByAscending("createdAt");
query.getFirstInBackground(new GetCallback() {
public void done(ParseObject object, ParseException e) {
if (object == null) {
Log.d("update", "The getFirst request failed.");
} else {
Log.d("update", "Retrieved the object.");
String update = object.getString("update");
Date time = object.getCreatedAt();
updateText = (TextView) table.getChildAt(i).findViewById(R.id.updateText);
timeText = (TextView) table.getChildAt(i).findViewById(R.id.timeText);
updateText.setText(update);
java.text.DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(getApplicationContext());
timeText.setText(dateFormat.format(time));
}
}
});
}
任何幫助,將不勝感激
似乎不起作用,因爲循環增量符'i'在else語句中不可用。我一直試圖選擇基於文本的行(這將匹配返回對象中的一個值)無濟於事。任何其他想法? – gregamariani
@ user1434163對不起,這是我的一個疏忽。我已經更新了我的答案,因此現在應該可以使用。 –
真棒...男人,我嘗試了很多不同的東西,但由於某種原因,這不是其中之一。你是一個拯救生命的人,我的項目現在可以前進!謝謝。 – gregamariani