Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ListView with clickable/editable widget

Is it possible to use a OnItemClickListener on a ListView when the Items layout has a clickable/editable widget (RadioButton,EditText, or CheckBox)?

like image 866
bugzy Avatar asked Jan 20 '10 01:01

bugzy


3 Answers

You might want to take a look at this issue. Having a focusable item in a row of a ListView causes the OnItemClickListener NOT to be invoked. However, that does not mean you cannot have focusable/clickable items in a row, there are some workarounds like this one.

Also, you can take a look at the Call Logs screen. It has a ListView with clickable item(the call icon on the right). See Source code here

like image 200
Samuh Avatar answered Oct 22 '22 03:10

Samuh


Quoting comment #31 in the link mentioned by Samuh (which solved the problem for me):

In fact you can add it to the layout XML (if inflated by one): android:descendantFocusability="blocksDescendants".

Adding here JIC that webpage is down in the future.

like image 44
khalid13 Avatar answered Oct 22 '22 02:10

khalid13


If any row item of list contains focusable or clickable view then OnItemClickListener won't work.

row item must be having param like android:descendantFocusability="blocksDescendants"

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:baselineAligned="false"
    android:descendantFocusability="blocksDescendants"
    android:gravity="center_vertical" >

    // your other widgets here

</LinearLayout>
like image 12
Bhavesh Hirpara Avatar answered Oct 22 '22 03:10

Bhavesh Hirpara