2014-09-19 37 views
1

我在parse.com中有一個名爲Messages的類。我創建了一個名爲「發送」類型字符串的列,其中存儲了消息必須發送到的用戶的對象標識。 在我的Android應用程序中,我想檢索當前用戶的消息。 但我的應用程序不顯示任何消息。如何從解析對象中獲取數據?

這是我如何實現它 -

public void done(List<ParseObject> postList, ParseException e) { 
setProgressBarIndeterminateVisibility(false); 
if (e == null) { 
// If there are results, update the list of posts 
// and notify the adapter 
posts.clear(); //posts is a list of <TextMessage> 
//TextMessage is a class which holds the details of Messages (parse object) 

for (ParseObject msg : postList) { 

if(msg.getParseUser("sent")==ParseUser.getCurrentUser()) 
{ 
    TextMessage note = new TextMessage(msg.getObjectId()); 
    posts.add(note); 
} 

} 
    ((ArrayAdapter<TextMessage>) getListAdapter()).notifyDataSetChanged(); 
} 

我不明白爲什麼,如果沒有得到執行的條件下,我在做什麼錯。 我還能如何檢索發送列中的字符串? 隨時要求提供更多所需信息。

+0

一個字符串對象中的結果爲真,如果(msg.getParseUser(「發送」)= = ParseUser.getCurrentUser()),比較字符串? – 2014-09-19 19:13:40

+0

是的,我在這裏比較字符串。 – Ish 2014-09-19 19:56:14

+0

閱讀文檔..返回類型的「getCurrentUser()'是一個用戶對象不是一個字符串.... ParseUser user = ParseUser.getCurrentUser(); – 2014-09-19 20:11:05

回答

1

我不是機器人專家,但我覺得你的問題是:

如果照顧你比較兩個字符串,則必須使用equals()==

變化==equals()一切正常

注意==檢查對象的引用是否相等。

注意equals()此方法將此字符串與指定的對象進行比較。當且僅當該參數不是null,並且是表示字符的相同序列與此對象

read about equals()

在此行
+1

它的工作就像一個魅力!非常感謝。 – Ish 2014-09-19 20:49:10

相關問題