ListView items that cannot be clicked using the HorizontalScrollView inside

I have a pretty 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 element is created ( getView() is called), I add a dynamic TextView to the LinearLayout inside the HorizontalScrollView (in addition to filling in another, simpler material). Surprisingly, the performance is very good.

My problem is that when I added HorizontalScrollView , my list items became unattractive. They do not get an orange background when clicked, and they do not start the OnItemClickedListener , which I set (to make a simple call to Log.d ).

How can I add list items again?


Edit: android:descendantFocusability="blocksDescendants" setting android:descendantFocusability="blocksDescendants" at the top of LinearLayout works. I would like to know if there are other ways: what if I want the objects to focus in my list items?

+6
android listview
source share
3 answers

Using android:descendantFocusability="blocksDescendants" at the top of LinearLayout did the trick. Elements inside can still be made β€œclickable”, they simply do not focus (that is, you cannot click them on a device without a touch screen). Good enough for me.

+8
source share

when I applied HorizontalScrollView to my TableLayout scroll, it works fine, but I can’t click on the My Layout list item as follwos

LinearLayout HorizontalScrollView TableLayout ......... / TableLayout / HorizontalScrollView / LinearLayout

i android application: descendantFocusability = "blocksDescendants" to my top most linearlayout Any help

0
source share
 android:descendantFocusability="blocksDescendants" 

didn't help me. So

So, I realized that the listener.

 public interface EventListItemOnClickListener { public void itemClicked(); } 

And in the adapter notify all listeners

 private List<EventListItemOnClickListener> listeners; protected void notifyOnClick(int position){ for(int i=0; i<listeners.size();++i) listeners.get(i).itemClicked((Event)events.get(position)); } ... @Override public void onClick(View v) { notifyOnClick(position); } ... 
0
source share

All Articles