I want to show friend list after log in to facebook through my app in a ListView
. But my code is not working. I have also used classes like friendsArrayAdapter. I have used following code
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.friendlist_screen);
facebook = new Facebook(APP_ID);
mAsyncRunner = new AsyncFacebookRunner(facebook);
lv = (ListView) findViewById(R.id.friendsList);
friendsArrayAdapter = new FriendsArrayAdapter(this, R.layout.rowlayout, friends);
lv.setAdapter(friendsArrayAdapter);
}
FriendsRequestListener.class
public class FriendsRequestListener implements com.facebook.android.AsyncFacebookRunner.RequestListener {
public void onComplete(final String response, Object state) {
mSpinner.dismiss();
try {
// process the response here: executed in background thread
Log.d("Facebook-Example-Friends Request", "response.length(): " + response.length());
Log.d("Facebook-Example-Friends Request", "Response: " + response);
final JSONObject json = new JSONObject(response);
JSONArray d = json.getJSONArray("data");
int l = (d != null ? d.length() : 0);
Log.d("Facebook-Example-Friends Request", "d.length(): " + l);
for (int i = 0; i < l; i++) {
JSONObject o = d.getJSONObject(i);
String n = o.getString("name");
String id = o.getString("id");
Friend f = new Friend();
f.id = id;
f.name = n;
friends.add(f);
}
// Only the original owner thread can touch its views
FrndActivity.this.runOnUiThread(new Runnable() {
public void run() {
friendsArrayAdapter = new FriendsArrayAdapter(
FrndActivity.this, R.layout.rowlayout, friends);
lv.setAdapter(friendsArrayAdapter);
friendsArrayAdapter.notifyDataSetChanged();
}
});
} catch (JSONException e) {
Log.w("Facebook-Example", "JSON Error in response");
}
}
Please sugest how to show the names in ListView and if I need to make any other classes for this thing?
MainActivity.java
Next.java