Answer the question
In order to leave comments, you need to log in
How to access an image in a ListView?
There is a ListView, the layout is specified in the adapter with the following structure:
I'm trying to access the imageView of a specific row:
LinearLayout temp = (LinearLayout) list.getAdapter().getView(position, null, list);
ImageView img = (ImageView) temp.getChildAt(0);
img.setImageResource(R.drawable.noava);
Answer the question
In order to leave comments, you need to log in
An approach like yours is wrong.
The content of the list is the responsibility of the adapter, and changes to that content from elsewhere will result in undefined rendering of the elements.
You need to define a method in the adapter:
In this method, you need to remember a new picture for the corresponding position and call the notifyDatasetChanged() method to update the contents of the list.
After that, the adapter will start updating, and you will be able to show the new picture that you previously saved.
It is clear from your code that you have not figured out how the ListView / RecyclerView works, read some tutorial on these components and then it will become clear to you what the problem was.
<ImageView android:id="@+id/imageView"
.../>
View view = list.getAdapter().getView(position, null, list);
ImageView imageView = view.findViewById(R.id.imageView);
imageView.setImageResource(R.drawable.noava);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question