How to get view from RecyclerView at specific adapter position and get values from those views?

六月ゝ 毕业季﹏ 提交于 2019-11-30 05:09:54

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/47826949/how-to-get-view-from-recyclerview-at-specific-adapter-position-and-get-values-fr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!