【发布时间】:2012-01-13 05:58:08
【问题描述】:
我想使用 Graph API 显示带有这些 cmets 和喜欢的 Facebook 页面的 Notes 项目。
为此,我在 Facebook SDK 中使用 asyncFacebookRunner。
步骤如下:
-
调用 asyncFacebookRunner.request 以获取带有 PageId 的 Note Item
mAsyncRunner.request(sAPIString, new NotesRequestListener(), null);
-
响应已经到来。 (我无法突出显示函数调用。很抱歉找到它。)
public class NotesRequestListener implements com.facebook.android.AsyncFacebookRunner.RequestListener { /** * Called when the request to get notes items has been completed. * Retrieve and parse and display the JSON stream. */ @Override public void onComplete(String response, Object state) { // TODO Auto-generated method stub Log.i("My_TAG", "onComplete with response, state"); try { // process the response here: executed in background thread final JSONObject json = new JSONObject(response); JSONArray arrNotesItems = json.getJSONArray("data"); int l = (arrNotesItems != null ? arrNotesItems.length() : 0); // !!!! // This has another request call // !!!! final ArrayList<WordsItem> newItems = WordsItem.getWordsItems(arrNotesItems,getActivity()); WordsActivity.this.runOnUiThread(new Runnable() { public void run() { wordsItems.clear(); wordsItems.addAll(newItems); aa.notifyDataSetChanged(); } }); // runOnUiThread } // try catch (JSONException e) { Log.i("My_TAG", "JSON Error in response"); } // catch } // onComplete ... other override methods ... } // Request Listener < Another Class > public static ArrayList<WordsItem> getWordsItems(JSONArray arrJSON, Activity activity) { ArrayList<WordsItem> wordsItems = new ArrayList<WordsItem>(); int l = (arrJSON != null ? arrJSON.length() : 0); try { WordsItem newItem; for (int i=0; i<l; i++) { JSONObject jsonObj = arrJSON.getJSONObject(i); String sTitle = jsonObj.getString("subject"); String sNoteID = jsonObj.getString("id"); ... get another fields here ... newItem = new WordItem(...); // !!!! // This has request call for comments // !!!! ArrayList<CommentItem> arrComment = getUserComments(sNoteID); wordsItems.add(newItem); } } catch (Exception e) { e.printStackTrace(); } return wordsItems; } // getWordsItems -
调用另一个 asyncFacebookRunner.request 以获取项目的 cmets(带有 NoteID)
在 getUserComments 中
mAsyncRunner.request(sAPIString, new CommentRequestListener(), null);
在获取cmets之前(CommentRequestListener中的OnComplete没有调用),getWordsItems返回item数组。
所以我看不到 cmets。
如何等待更新 UI 直到获得 cmets? (同步异步调用真是太讽刺了。)
提前致谢。
【问题讨论】:
标签: android facebook asynchronous comments