如何从特定适配器位置的RecyclerView获取视图并从这些视图获取值? [英] How to get view from RecyclerView at specific adapter position and get values from those views?

查看:302
本文介绍了如何从特定适配器位置的RecyclerView获取视图并从这些视图获取值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有RecyclerView,每个行布局都有一个ImageView和一个TextView.在RecyclerViewAdapter的ViewHolder中,我有一个单击侦听器

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 
                }
            }

请帮助从Recyclerview获取特定适配器位置的视图,以反映我的问题的图像如下

Please help to get view at specific adapter position from Recyclerview Image to reflect my problem is as follows

推荐答案

尝试使用 recyclerView.getLayoutManager().findViewByPosition(int position) 来获取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);

注意:-滚动recyclerView时,只有显示在屏幕上的项目超过从内存中删除的项目

NOTE :- only item that is display in screen when you scroll recyclerView than item will removed from memory

-您可以在adapter中编写一个公共方法,以使您的arraylist进入活动中,您可以在其中检查标志

EDIT :- you can write a public method in adapter to get your arraylist in your activity where you can check your flag

这篇关于如何从特定适配器位置的RecyclerView获取视图并从这些视图获取值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆