I have RecyclerView having an ImageView and a TextView for each row layout.In ViewHolder in RecyclerViewAdapter, I have click listener as
v.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Images i=list.get(getAdapterPosition());
i.setFlag(!i.getFlag());
list.set(getAdapterPosition(),(i));
notifyDataSetChanged();
}
});
In that click listener I am changing Boolean flag such that it can show either an item is selected or not.Depending on it's value I want to Traverse entire ArrayList by checking
for(int i=0; i<images.size(); i++){
if(images.get(i).getFlag()){
// there I want to get view from LayoutManager for that item
//but how to get view for that item and get Bitmap form imageview for that item
//end of geting view
}
}
Please help to get view at specific adapter position from Recyclerview Image to reflect my problem is as follows
The RecyclerView. ViewHolder class provides us a method called getAdapterPosition which will return the proper position of anything that currently drawn on the RecyclerView. So, the way I fix the problem I had is by changing the position into viewHolder. getAdapterPosition() .
You do not have to use any extra method. Just create a global variable named 'position' and initialize it with getAdapterPosition() in any of the major method of the adapter (class or similar). Here is a brief documentation from this link. getAdapterPosition added in version 22.1.
Adapter: Provides a binding from your app's data set (which is specific to your app) to item views that are displayed within the RecyclerView . The adapter knows how to associate each item-view position in the RecyclerView to a specific location in the data source.
Try this use recyclerView.getLayoutManager().findViewByPosition(int position)
to get particular row of recyclerView
View row = recyclerView.getLayoutManager().findViewByPosition(0);
TextView textView = row.findViewById(R.id.YourTextviwID);
textView.setText("Nilu");
ImageView textView = row.findViewById(R.id.YourImageViewID);
imageView.setBackgroundResource(R.mipmap.ic_launcher);
NOTE :- only item that is display in screen when you scroll recyclerView than item will removed from memory
EDIT :- you can write a public method in adapter
to get your arraylist
in your activity where you can check your flag
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With