2

I've got a big headache and spent a few hours to solve my problem withou any reasonable results.

I use a custom adapter (extending ArrayAdapter) to show listview items. This adapter implements OnTouchListener. There's also a background selector which color is changing when an item is touched and OnItemClickListener in ListViewActivity.

What I need is capture touch events (all of them, not only ACTION_DOWN) in the adapter. When onTouch returns false, the consecutive events (ACTION_CANCEL, ACTION_UP etc.) aren't captured. On the other hand returning true stops dispatching all other events (e.g. click) so that the ListViewActivity's onItemClick is never triggered.

I tried hard to find any working solution in SO and other resources, but with no success.

One idea was not worry about click events and background. I may set the background programatically and trigger click event the same way when the onTouch action is ACTION_UP, but view.performClick() does nothing (view is the 1st argument of onTouch method).

[EDIT]

To make it clear, I want to handle touch events in the adapter beacuse I need the textview in the item to marquee when the user touches it. Thus, in onTouch, when the action equals ACTION_DOWN, I assign true to setSelected property of the textview and, consequently, false when ACTION_CANCEL or ACTION_UP.

Any suggestions?

Thanks in advance.

peterp
  • 171
  • 1
  • 1
  • 9
  • `ListView`-s are a pain to use, it's better to avoid them and use `LinearLayout` + `ScrollView` if possible. Also checkout these 2 functions about intercepting touch events: [onInterceptTouchEvent()](http://developer.android.com/reference/android/view/ViewGroup.html#onInterceptTouchEvent%28android.view.MotionEvent%29) , [requestDisallowInterceptTouchEvent()](http://developer.android.com/reference/android/view/ViewGroup.html#requestDisallowInterceptTouchEvent%28boolean%29) , [more info](http://developer.android.com/training/gestures/viewgroup.html) – gregn3 Mar 28 '13 at 12:33

0 Answers0