Reputation: 169
I want to load images from facebook and populate in listview, i am able to get list of friends and their info but i want to set image i am getting getChildCount() 0 , please help,
public static ArrayList<FBUser> fbUserArrayList;
public static Drawable sharedDrawable;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.friends_list_view);
this.setTitle("FB Friend List");
final ListView listView = (ListView) findViewById(R.id.listview);
FriendListAdapter couponsListAdapter = new FriendListAdapter(this,
fbUserArrayList);
listView.setAdapter(couponsListAdapter);
couponsListAdapter.notifyDataSetChanged();
setFbUsersImage(listView,fbUserArrayList);
}
private void setFbUsersImage(final ListView listView,final ArrayList<FBUser> fbUserArrayList) {
// here am getting 0 ???
for (int i = 0; i < listView.getChildCount(); i++) {
////
}
}
Upvotes: 6
Views: 4678
Reputation: 86958
The ListView has not been drawn yet so it doesn't have any children. Unfortunately there is no callback, like onResume()
, for when a View has been drawn, but you can use a Runnable to do what you want.
Addition
Let's make a couple changes in onCreate()
:
listView.setAdapter(couponsListAdapter);
// Remove your calls to notifyDataSetChanged and setFbUsersImage
// Add this Runnable
listView.post(new Runnable() {
@Override
public void run() {
setFbUsersImage(listView,fbUserArrayList);
}
});
You need to make listView
a field variable just like fbUserArrayList
. Now setFbUsersImage()
will be run when the ListView has children.
All that said, if you are trying to modify the row in any way, the adapter is the best place to do this.
Upvotes: 21