OnItemClickListener doesn't work with ListView item containing button
Solution 1
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
Solution 2
If you have ImageButtons inside the list item, you need to add:
android:descendantFocusability="blocksDescendants"
to the root list item element [such as the root layout].
Then within each ImageButton in the list item, you need to add:
android:focusableInTouchMode="true"
This worked for me - but I was using ImageButtons, not the standard button.
Solution 3
I have also faced the same issue I have tried to set android:focusable="false"
to listview but it don't work then I add this to listview item.. like in my listview item I have uesed Toggle button which was creating problem, I add android:focusable="false"
to Toggle button and listview on item click listener start work again
Solution 4
Add following line to your listView
android:choiceMode="singleChoice"
or make sure to set following lines to your layout text fields
android:focusable="false"
android:focusableInTouchMode="false"
android:clickable="false"
Barmaley
Не программист, не кодер, не девелопер, не архитектор, не тестер и вообще не айтишник. Зовите меня просто Гуру Java/Android :) Иногда изображаю крутизну: С/С++/C#/SQL/WMS/ERP Нетрадиционные познания: Schroedinger/Navier-Stokes
Updated on July 20, 2020Comments
-
Barmaley almost 4 years
I have
ListView
with customAdapter
which suppliesView
toListView
in this way:public View getView(int position, View convertView, ViewGroup parent) { RelativeLayout.LayoutParams lineParams; RelativeLayout line=new RelativeLayout(context); TextView tv=new TextView(context); tv.setText("Text in postion="+i); lineParams=new RelativeLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); lineParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT); line.addView(tv, lineParams); lineParams.addRule(RelativeLayout.CENTER_IN_PARENT); //checkbox CheckBox checkBox=new CheckBox(context); lineParams=new RelativeLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); lineParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); lineParams.addRule(RelativeLayout.CENTER_IN_PARENT); line.addView(checkBox, lineParams); return line; }
And somewhere inside
ListView
there'ssetOnItemClickListener()
, which should intercept item clicking events. My problem that, whenever I try to add checkbox to item - I don't get any responces from myListView
. If I skipCheckBox
or any otherButton
it works.I am really stuck with this problem, I have tried all kind of Layouts, aligning, wrapping and so on - useless. Looks like
CheckBox
interferesListView
item click events.Any ideas how to overcome?