[英]How to get view from RecyclerView at specific adapter position and get values from those views?
我有RecyclerView,每個行布局都有一個ImageView和一個TextView。在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
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.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);
注意: - 只有在滾動recyclelerView時顯示在屏幕上的項目才會從內存中刪除
編輯: - 你可以在adapter
編寫一個公共方法,讓你的活動中的arraylist
可以檢查你的旗幟
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.