What Does It Mean If findViewById finds view but setText or setImageResource Do not work

StackOverflow https://stackoverflow.com/questions/23492986

سؤال

This problem is really driving me mad. I have spent 2-3 days just trying to pass it. I have a listview, I iterate through each list element to set their images from a drawable. I checked if findViewById works, and it does because logcat gave me the id it had. When I try to setImageResource or use Picasso to load the image from the internet nothing happens and the images do not appear.

Here is the ImageView definition in the XML:

 <ImageView
 android:id="@+id/Photo"   
 android:layout_height="100dp"
 android:layout_width="100dp"
 android:contentDescription="@string/desc"
  />

And here is the iteration process:

for (int i = 0; i < list.getCount(); i++) {


                   v = mAdapter.getView(i,null, list);

                  ImageView photo = (ImageView) v.findViewById(R.id.Photo);

                   photo.setImageResource(R.drawable.abc_ab_bottom_solid_dark_holo);
               }

It looks a very simple task to do but for some reason it is not working. I tried cleaning the project if that might matter. Also, This is all in a fragment, and I have already used setAdapter on the list.

I really appreciate any help..

هل كانت مفيدة؟

المحلول

Adapter getView() gives you a new view. It's not the same that is displayed on screen and changing it doesn't have any visible results.

Move the setImageResource() code to the adapter getView() itself so it operates on the same views as requested by your list view.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top