如何从特定适配器位置的 RecyclerView 获取视图并从这些视图中获取值?
How to get view from RecyclerView at specific adapter position and get values from those views?
我有 RecyclerView,每行有一个 ImageView 和一个 TextView layout.In RecyclerViewAdapter 中的 ViewHolder,我有点击监听器
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();
}
});
在那个点击侦听器中,我正在更改布尔标志,以便它可以显示一个项目是否被选中。根据它的值我想通过检查 [=遍历整个 ArrayList =13=]
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 获取特定适配器位置的视图反映我的问题的图像如下
尝试使用 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 时屏幕上显示的项目才会从内存中删除
编辑:- 您可以在 adapter
中编写一个 public 方法,以便在您的 activity 中获取您的 arraylist
,您可以在其中检查您的标志
我有 RecyclerView,每行有一个 ImageView 和一个 TextView layout.In RecyclerViewAdapter 中的 ViewHolder,我有点击监听器
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();
}
});
在那个点击侦听器中,我正在更改布尔标志,以便它可以显示一个项目是否被选中。根据它的值我想通过检查 [=遍历整个 ArrayList =13=]
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 获取特定适配器位置的视图反映我的问题的图像如下
尝试使用 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 时屏幕上显示的项目才会从内存中删除
编辑:- 您可以在 adapter
中编写一个 public 方法,以便在您的 activity 中获取您的 arraylist
,您可以在其中检查您的标志