How to access the image in the ListView?

There is a ListView in the adapter specified layout with this structure:
Trying to access imageView in a particular row:
LinearLayout temp = (LinearLayout) list.getAdapter().getView(position, null, list);
 ImageView img = (ImageView) temp.getChildAt(0);
 img.setImageResource(R. drawable.noava);

Compiles without errors, when working, no crashes, however the picture in the coveted line it's still not changing. What am I doing wrong?
PS do not judge strictly, I'm new
July 8th 19 at 15:39
2 answers
July 8th 19 at 15:41
This approach, like You - wrong.
For the contents of the list meets the adapter and modify content from other places will cause undefined display elements.
You need the adapter to define a method:

updateImage(int position, int imageResId);

In this method you have to memorize a new picture for the item in question and call the method notifyDatasetChanged () to update the contents of the list.
After that, the adapter will start the update and You will be able to show a new image that you previously saved.
Your code shows that You don't understand how it works the ListView/RecyclerView, read some tutorial on these components and then it becomes clear what the problem was.
July 8th 19 at 15:43
<imageview android:id="@+id/imageView" ...></imageview>

View View = list.getAdapter().getView(position, null, list);
ImageView imageView = view.findViewById(R. id.imageView);
imageView.setImageResource(R. drawable.noava);

Only this must be done in the adapter itself.
did as you advised, still the picture does not update( - Humberto_Blan commented on July 8th 19 at 15:46
: well, nothing. PHP govnokoder trying Android don't need to listen. Above you said that it is the adapter. - Art_Christians commented on July 8th 19 at 15:49
: I just wanted to help people, why so harsh? Because you can just correct me or complain of the answer. Or somewhere I sinned? - brando commented on July 8th 19 at 15:52
: You sinned that climb with sovim bad code to help newcomers. Go first learn the materiel, then come, tell me, welcome to my blog. - Art_Christians commented on July 8th 19 at 15:55
: OK, I won't write down answers, just a shame to see such comments when sincerely trying to help. - brando commented on July 8th 19 at 15:58

Find more questions by tags JavaAndroid