I have an imageswitcher as the only component on the screen. I want to capture the swipe gesture and click event separately for it. But it is not able to get the events separately. If I set the onclicklistener method for imageswitcher object then it always fires onclick method even if I have swiped.
Can someone let me know the workaround to this?
If you return true from your onFling(…) it should consume the event and stop propagation.
Ref from this question:
android - giving onTouch priority over onClick
Related
I need to create a click event, that's not being consumed, so that an underlying adapter receives the touch event.
I cant use an OnClickListener, because that would consume the event.
I tried my best with OnTouchListener, but if I return true the event gets consumed and if I return false the listener only registers ACTION_DOWN events.
How can I react on a click, but if its not a click the adapter will receive the move?
EDIT:
I'm using a lorentzos.swipecards SwipeFlingAdapterView, which uses touch-move-events. I put a layout over half of the view of the items of the adapter, which need to react on click events. But I either can't implement the click event, since I can't catch two events in a row without consuming them, or I can't have the SwipeFlingAdapterView react on the touch-move-event, since I, well, consumed it in the click event.
Don't know what sourcecode to share, since I tried many different ways and nothing works.
I have a button , on which calling onTouchListener , I want to set different behavior . 1. if it is being pressed ,
2.when user just touch the button
You're probably better off using an OnLongClickListener rather than an onTouch. You can set one just like an onClick and it will call you when a press and hold has occurred.
If you did want to implement it via onTouch, you'd set a timer in the touchDown. If the user has a touchUp, cancel the timer. If not, when the timer goes off it is now a touch and hold and you perform whatever behavior you wanted to.
I'm trying to create a drag-drop interface for a ExpandableListView.
I wanted to know if there is a function similar to OnChildClickListener for OnTouch?
If not, what would be the best way of listening for a touch event on a child inside the expandable list?
I realized we could add an OnTouchListener() in getChildView(). That would listen for a touch event every time the user touches the child item.
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.
I have some problem - I must know when the button isn't clicked anymore. I need something like onClickListener which is executed when the user stops holding his finger on the button. Is it even possible?
Use onTouchListener and check for MotionEvent ACTION_UP (return true in your implementation to make Android know that you are handling the whole Touch event)
Yes. What you should do is register on touch handler:
button.setOnTouchListener(listener)
and in the listener you should check the event if it's action is ACTION_UP. That's all.