我试图在项目视图中填写一个注释/消息列表复选框.
我已经尝试将侦听器设置为复选框.遗憾的是,复选框点击没有任何反应.
如果我将监听器设置为父视图.它能够触发onClick方法.但每次用户点击列表中的整个项目时都会触发此 *** 作.
我的目标更多是关于为复选框设置监听器.
很难知道用户已从列表中选择了注释.
继承我的代码适配器类和视图持有者内部类
public class broadcastRVA extends RecyclerVIEw.Adapter<broadcastRVA.broadcastVH>{private Context mContext;private ObservableArrayList<MNote> notes;private LayoutInflater inflater;public broadcastRVA(Context mContext, ObservableArrayList<MNote> notes, LayoutInflater inflater) { this.mContext = mContext; this.notes = notes; this.inflater = LayoutInflater.from(mContext);}@OverrIDepublic broadcastRVA.broadcastVH onCreateVIEwHolder(VIEwGroup parent, int vIEwType) { NoteListitembinding binding = NoteListitembinding.inflate(inflater); VIEw vIEw = LayoutInflater.from(parent.getContext()).inflate( R.layout.note_Listitem, null); broadcastVH vIEwHolder = new broadcastVH(binding, vIEw); // create a new vIEw return vIEwHolder;}@OverrIDepublic voID onBindVIEwHolder(broadcastVH holder, final int position) { final MNote note = notes.get(position); holder.cBox.setChecked(note.isSelected()); holder.cBox.setTag(note); holder.vBinding.setNote(note); holder.cBox.setonClickListener(new VIEw.OnClickListener() { public voID onClick(VIEw v) { CheckBox cb = (CheckBox) v; MNote note = (MNote) cb.getTag(); note.setIsSelected(cb.isChecked()); notes.get(position).setIsSelected(cb.isChecked()); Toast.makeText( v.getContext(), "Clicked on CheckBox: " + cb.getText() + " is " + cb.isChecked(), Toast.LENGTH_LONG).show(); } });}public ObservableArrayList<MNote> getNotes() { return notes;}/** * Returns the total number of items in the data set hold by the adapter. * * @return The total number of items in this adapter. */@OverrIDepublic int getItemCount() { if (notes != null) return notes.size(); else return 0;}public class broadcastVH extends RecyclerVIEw.VIEwHolder { NoteListitembinding vBinding; TextVIEw uuID; CheckBox cBox; public broadcastVH(NoteListitembinding binding, VIEw vIEw) { super(binding.getRoot()); this.vBinding = binding; this.uuID = (TextVIEw) vIEw.findVIEwByID(R.ID._UUID); this.cBox = (CheckBox) vIEw.findVIEwByID(R.ID.deleteNote); } }}
note_List_item.xml
<?xml version="1.0" enCoding="utf-8"?><layout xmlns:androID="http://schemas.androID.com/apk/res/androID"> <data> <variable name="note" type="com.pbasolutions.androID.model.MNote" /> </data> <linearLayout androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:orIEntation="vertical" androID:weightSum="1"> <tableLayout androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content"> <tableRow androID:layout_wIDth="match_parent" androID:layout_height="match_parent" > <CheckBox androID:layout_wIDth="30dp" androID:layout_height="wrap_content" androID:ID="@+ID/deleteNote" androID:clickable="true"/> <TextVIEw androID:layout_wIDth="270dp" androID:layout_height="wrap_content" androID:ID="@+ID/textVIEwNote" androID:layout_column="1" androID:layout_marginleft="5dp" androID:text="@{note.textMsgs}" androID:editable="false" androID:textSize="22sp"/> <tableLayout androID:layout_column="1"> <tableRow> <TextVIEw androID:layout_wIDth="80dp" androID:layout_height="wrap_content" androID:ID="@+ID/textVIEwNoteDate" androID:layout_column="0" androID:text="@{note.date}" androID:editable="false" androID:textSize="15sp"/> </tableRow> </tableLayout> <TextVIEw androID:layout_wIDth="270dp" androID:layout_height="wrap_content" androID:ID="@+ID/_UUID" androID:layout_marginleft="5dp" androID:text="@{note._UUID}" androID:visibility="invisible"/> </tableRow> </tableLayout> <VIEw /> </linearLayout></layout>
解决方法:
什么是NoteListitembinding?一般来说,单击复选框时必须触发onClick方法,当您单击视图时,视图组将首先接收触摸事件,然后将事件传递给其子视图,但如果视图组阻止该事件,则事件将被消耗,并且子项无法获取事件,其onClick方法不会被触发.
总结以上是内存溢出为你收集整理的android – 使用DataBinding在RecyclerView上复选框监听器全部内容,希望文章能够帮你解决android – 使用DataBinding在RecyclerView上复选框监听器所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)