Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setOnItemClickListener() not working on custom ListView @ Android

I have Implemented a custom ListView by extending LinearLayout for every row. Every row has a small thumbnail, a text and a check box. The list view is deployed properly and I can scroll and fling through it without any problems.

But The ListView doesn't seem to respond to the setOnItemClickListener() at all, So I had to find a workaround by setting click listener in the getView() of the Text inside every row which is obviously creating problem when I am trying to reuse the adapter. Does anyone have a solution?

like image 322
Sameer Avatar asked Oct 05 '09 05:10

Sameer


3 Answers

Try this
For ListView,

final ListView list = (ListView) findViewById(R.id.list);
list.setItemsCanFocus(false);

Also, make sure that for CheckBox inside list item set focusable false

android:focusable="false"
android:focusableInTouchMode="false"
like image 154
bhatt4982 Avatar answered Oct 10 '22 17:10

bhatt4982


old answer: I wrote in previous post here

android:focusable="false"
android:clickable="false"

will not help when ImageButton is in custom view.. One must use button.setFocusable(false); during runtime (from java source code)

Edit: There is even more elegant solution. Try to add android:descendantFocusability="blocksDescendants" in root layout of list element. That will make clicks onListItem possible and separately u can handle Button or ImageButton clicks

like image 28
Ewoks Avatar answered Oct 10 '22 17:10

Ewoks


For a ListView where you set the item views to CheckBox

android:focusable="false"
android:clickable="false"

http://code.google.com/p/android/issues/detail?id=3414

like image 26
Tomas Avatar answered Oct 10 '22 15:10

Tomas