I get listView.getChildCount (), 0 after setting arrayadapter?

I want to upload images from facebook and fill in listview, I can get a list of friends and their information, but I want to set an image, I get 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++) { //// } } 
+6
source share
1 answer

ListView has not been created yet, so it has no children. Unfortunately, there is no callback such as onResume() when the View was created, but you can use Runnable to do what you want.


Adding
Make a couple of changes to 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 field variable just like fbUserArrayList . Now setFbUsersImage() will be fired if the ListView has children.

All that said, if you are trying to modify the string in any way, the adapter is best for this.

+18
source

All Articles