public class MyRecyclerVIEwAdapter extends RecyclerVIEw.Adapter<MyRecyclerVIEwAdapter.DataObjectHolder> {private static String LOG_TAG = "MyRecyclerVIEwAdapter";private ArrayList<CRMbean> mDataset;private static MyClickListener myClickListener;static Context mContext;private List<String> mtList ;public MyRecyclerVIEwAdapter(List<String> filteredList,CRMactivity crMactivity) { mtList = filteredList;}public static class DataObjectHolder extends RecyclerVIEw.VIEwHolder implements VIEw .OnClickListener { public static ImageVIEw testimage; TextVIEw name; TextVIEw regID; TextVIEw roomNo; public DataObjectHolder(VIEw itemVIEw) { super(itemVIEw); name = (TextVIEw) itemVIEw.findVIEwByID(R.ID.name); regID = (TextVIEw)itemVIEw.findVIEwByID(R.ID.reg_ID); roomNo = (TextVIEw)itemVIEw.findVIEwByID(R.ID.roomno); testimage = (ImageVIEw)itemVIEw.findVIEwByID(R.ID.logo); Log.i(LOG_TAG,"Adding Listener"); itemVIEw.setonClickListener(this); } @OverrIDe public voID onClick(VIEw v) { myClickListener.onItemClick(getAdapterposition(),v); }}public voID setonItemClickListener(MyClickListener myClickListener) { MyRecyclerVIEwAdapter.myClickListener = myClickListener;}public MyRecyclerVIEwAdapter(ArrayList<CRMbean> myDataset) { mDataset = myDataset;}@OverrIDepublic MyRecyclerVIEwAdapter.DataObjectHolder onCreateVIEwHolder(VIEwGroup parent,int vIEwType) { VIEw vIEw = LayoutInflater.from(parent.getContext()) .inflate(R.layout.card_vIEw_row,parent,false); DataObjectHolder dataObjectHolder = new DataObjectHolder(vIEw); return dataObjectHolder;}@OverrIDepublic voID onBindVIEwHolder(MyRecyclerVIEwAdapter.DataObjectHolder holder,int position) { holder.name.setText(mDataset.get(position).getname()); holder.regID.setText(mDataset.get(position).getRegID()); holder.roomNo.setText(mDataset.get(position).getRoomNo());}public voID addItem(CRMbean dataObj,int index) { mDataset.add(index,dataObj); notifyItemInserted(index);}public voID deleteItem(int index) { mDataset.remove(index); notifyItemRemoved(index);}@OverrIDepublic int getItemCount() { return mDataset.size();}public interface MyClickListener { voID onItemClick(int position,VIEw v);}
}
以上是适用于recyclervIEw的adpater
((MyRecyclerVIEwAdapter) mAdapter).setonItemClickListener (new MyRecyclerVIEwAdapter.MyClickListener() { @OverrIDe public voID onItemClick(int position,VIEw v) { Log.i(LOG_TAG," Clicked on Item " + position); MyRecyclerVIEwAdapter.DataObjectHolder.testimage.setimageResource(R.drawable.vIDeo_icon_fill); //getinformation(position); } });
上面的代码适用于OnclickListener
解决方法 试试这个,class CRMbean{ public boolean isImageChanged; public boolean isImageChanged() { return isImageChanged; } public voID setimageChanged(boolean imageChanged) { isImageChanged = imageChanged; }}
在BindHolder上做它,
@OverrIDepublic voID onBindVIEwHolder(MyRecyclerVIEwAdapter.DataObjectHolder holder,int position) { holder.name.setText(mDataset.get(position).getname()); holder.regID.setText(mDataset.get(position).getRegID()); holder.roomNo.setText(mDataset.get(position).getRoomNo());if(mDataset.get(position).isImageChanged()){ holder.testimage.setimageResource(R.drawable.vIDeo_icon_fill);}else{ holder.testimage.setimageResource("You Default Image");}}
在Adapter上写这个方法
public voID changeImage(int index) { mDataset.get(position).setimageChanged(true); notifyItemChanged(index)}
在项目上单击RecylevIEw
(MyRecyclerVIEwAdapter) mAdapter).setonItemClickListener (new MyRecyclerVIEwAdapter.MyClickListener() { @OverrIDe public voID onItemClick(int position," Clicked on Item " + position); MyRecyclerVIEwAdapter.changeImage(position); } });总结
以上是内存溢出为你收集整理的android – 如何在单击后更改回收器视图中的特定图像全部内容,希望文章能够帮你解决android – 如何在单击后更改回收器视图中的特定图像所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)