OnItemClickListener doesn't work with ListView item containing button

后端 未结 8 1777
广开言路
广开言路 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.

    0 讨论(0)
  • 2020-12-01 18:35

    just add this line into the item views instead of listView itself

    android:focusable="false"
    

    check more detail about this from Android custom ListView unable to click on items

    0 讨论(0)
提交回复
热议问题