OnItemClickListener doesn't work with ListView item containing button

后端 未结 8 1778
广开言路
广开言路 2020-12-01 17:33

I have ListView with custom Adapter which supplies View to ListView in this way:

   public View getView(i         


        
8条回答
  •  离开以前
    2020-12-01 18:23

    Well i know none of the above solutions will work.I tried changing xml attributes but those does not work out, But i implemented it in a new fashion. Here is how:

    Create an interface CheckBoxOnCheckListener with method onCheckBoxChecked and pass needed parameters, implement interface CheckBoxOnCheckListener in your activity or fragment containing listView.

    Next in your adapter, declare an mListener as CheckBoxOnCheckListener, and pass this as a parameter to Adapter's constructor from fragment/activity and cast it to CheckBoxOnCheckListener and assign to mListener.

    Next set mListener as itemView.onClick or CheckBox.onCheckCheckedListener and onCheckChanged method call mListener.onCheckBoxChecked.

    That's it. It will definitely work,it worked for me. For code just pm.

提交回复
热议问题