I want to show Facebook Page's Notes items with those comments and likes using Graph API.
To do that, I'm using the asyncFacebookRunner in Facebook SDK.
Steps are like this:
call asyncFacebookRunner.request to get Note Item with PageId
mAsyncRunner.request(sAPIString, new NotesRequestListener(), null);
Response has come. ( I can't highlight function call. Sorry for inconvenient to find it.)
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
call another asyncFacebookRunner.request to get comments of item(with NoteID)
in getUserComments
mAsyncRunner.request(sAPIString, new CommentRequestListener(), null);
Before getting comments(OnComplete in CommentRequestListener has not called), getWordsItems returns item array.
So I can't see the comments.
How can I wait to update UI till getting comments? (It's so ironic to synchronize asynchronized calls.)
Thanks in advance.