Skip to content Skip to sidebar Skip to footer

Calling Setadapter In Facebook Oncomplete

I'm using the Facebook API and I'm having a hard time getting a ListView to show data. My code uses fragments and inflates a layout that has a ListView as the root. That ListView i

Solution 1:

this is happening because

refreshFeedList = (PullToRefreshListView) view.findViewById(R.id.feedList);
feedList = refreshFeedList.getRefreshableView();
feedList.setDividerHeight(0);

this code is executed before:

feedList.setAdapter(endlessAdapter);

in onComplete. cause u have called initialFeedRequest.executeAsync();, that means the request is executed in a different thread beside UI-Thread . u have to execute

refreshFeedList = (PullToRefreshListView) view.findViewById(R.id.feedList);
feedList = refreshFeedList.getRefreshableView();
feedList.setDividerHeight(0);

after onComplete done its job

and another thing, u should return a view from onViewCreate() because its return type is View

Edited:

put your responseObject in SharedPreference in onCopmlete:

SharedPreferencesprefs= PreferenceManager.getDefaultSharedPreferences(getActivity());
SharedPreferences.Editoreditor= prefs.edit();
editor.putString("responseObject", responseObject.toString());
editor.commit();

getback your responseObject in else condition:

JSONObject responseObject;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
String responseObjectString = prefs.getString("responseObject");
if(responseObjectString != null) 
    responseObject = newJSONObject(responseObjectString);
newsFeed = responseObject.getJSONArray("data");

feedAdapter = newFeedAdapter(getActivity(), newsFeed); // use the newsFeed we get from SP
endlessAdapter = newEndlessFeed(feedAdapter);
feedList.setAdapter(endlessAdapter);
refreshFeedList.setOnRefreshListener(refreshListener);

if u want to use Application class then see: Application class tutorial

then u have to change your manifest also:

<application 
   android:label="@string/app_name"
   android:allowBackup="true"
   android:icon="@drawable/ic_launcher"
   android:name=".Your_Application_class_name">
// other components. ....

</application>

Post a Comment for "Calling Setadapter In Facebook Oncomplete"