Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ListView items not clickable with HorizontalScrollView inside

I have quite a complicated ListView. Each item looks something like this:

> LinearLayout (vertical)
  > LinearLayout (horizontal)
    > include (horizontal LinearLayout with two TextViews)
    > include (ditto)
    > include (ditto)
  > TextView
  > HorizontalScrollView (this guy is my problem)
    > LinearLayout (horizontal)

In my activity, when an item is created (getView() is called) I add dynamic TextViews to the LinearLayout inside the HorizontalScrollView (besides filling the other, simpler stuff out). Amazingly, performance is pretty good.

My problem is that when I added the HorizontalScrollView, my list items became unclickable. They don't get the orange background when clicked and they don't fire the OnItemClickedListener I have set up (to do a simple Log.d call).

How can I make my list items clickable again?


Edit: setting android:descendantFocusability="blocksDescendants" on the topmost LinearLayout seems to work. I'd like to know if there are other ways, though: what if I want focusable items in my list items?

like image 879
Felix Avatar asked Jun 06 '10 21:06

Felix


1 Answers

Using android:descendantFocusability="blocksDescendants" on the topmost LinearLayout did the trick. Elements inside can still be made "clickable", they're just not focusable (i.e. you can't click them on a non-touchscreen device). Good enough for me.

like image 91
Felix Avatar answered Sep 30 '22 19:09

Felix