I want to simulate a swipe event in Android app.this link is for touch event
Basically I want to slide to the next view when a user swipe on the screen or when he click a button, and the first one is trivial. The second one is complecated that I have to simulate or trigger a swipe event in the OnClickListener of the Button. How can I do that?
If you already use ViewPager
viewpager.setCurrentItem(i)
where i is a numer of page you want slide into
Related
My use case is, that I need to hide the toolbar and bottom navigation view after a delay and reveal it once the user taps anywhere on the screen.
But I shouldn't reveal those when the user touches the screen to click on a View/Compose or when the user performs a swipe/scroll gesture.
I achieved this partially using GestureDetectorCompat.onSingleTapConfirmed. The gesture detector doesn't call this method for swipe gestures, but it calls this for click events for clickable views/compose inside the screen.
So when I click an actionable icon in the screen, that click action is executed and the toolbar and bottom bars are revealed. I need to ignore the tap events when the tap occurs on a clickable view/compose.
I mention as view/compose because, my project has both XML-based views and Compose views, so the solution should work for both click events.
Any help is much appreciated, thanks.
I want to display two buttons after one button is long pressed and achieve their selection via user's swipe to up/left direction without giving in a second touch event.
I tried GestureDetector onLongPress to show buttons and then:
onFling-> user needs to provide a fling action to achieve selection. Not desired behaviour (in android keyboard key, user can select option without lifting his finger)
onScroll-> I can't get the ACTION_UP. And, user needs to touch twice.
how to detect a swipe triggered on a view after it's being long pressed in android (single touch event) e.g. it's done for a keyboard (9-key format) key?
I need to do:
action_1 on normal click
action_2 on long click (showing buttons) and checking their selection by swipe in single touch event of long click
Please help..!
I am trying to drag a view from one place to another and also have a single click/tap to do a completely different action without dragging the view.
Right now what I have a long click listener to start my drag like this
view.setOnLongClickListener(..
....
view.startDrag(...
And for my single click I use a click listener like this
view.setOnClickListener(...
// My completely different action
How can I have it so that I don't have to use long click to start drag, but can start drag by allowing user to just simply move his/her finger from my view to the target.
Use view.setOnTouchListener(..
the function will be called as soon as you touch the item. In this function, you should call your view.startDrag(... function and you are good to go.
Have fun and Take Care.
use a delay thread inside on touch listner
because on click works when you remove your finger dragging cant be done after removing finger
I want to detect gesture on my ScrollView and its childs . I wanna have all those onClick method working as well. Say there is a button surrounded with LinearLayout and the whole thing is surrounded with ScrollView . I wanna call an action when user swipe anywhere of the ScrollView..
I applied onTouchListener to ScrollView.. But as the LinearLayout is clickable, event isn't fired when I swipe over the linear layout.
and if I set touch listener to all those child view, then onclick doesn't work.
remebmer using facebook lite ? user reads, scrolls news feed taps "like" button. clicks on links.. But still it can show chat list when user swipes from right to left on any part of screen.. how do they do it ?
You don't need onTouchListener to do this job for you. Use onScrollChangedListener. See this answer for more info Can I have onScrollListener for a ScrollView?. This question has been answered many times all over internet.
So I have made a swipe function that allows the user to swipe menus from the top of the screen and the side of the screen (Note: There are arrows that are peaking in from the sides of the screen that the user is garbing to swipe the menu in). Now it all works great, but for one thing... The menu's will only work with the .stage in there event listeners. This wouldn't be a problem but I have screens that also are using a swipe function to change what is on the screen. But the odd thing is that the screens using the swipe function do not need the .stage in there event listener. Below I will post the event listeners, I've been stuck on this for a few days just does not add up to me on why it's doing this.
//Side Menu Swipe
smenu_mc.stage.addEventListener(TransformGestureEvent.GESTURE_SWIPE, onSwipe);
//Top Menu Swipe
tmenu_mc.stage.addEventListener(TransformGestureEvent.GESTURE_SWIPE, downSwipe);
//Screens Swipe
Games.addEventListener(TransformGestureEvent.GESTURE_SWIPE, lrSwipe);
What you can do, is on swipes that will be occurring on-top of a display object (like presumable your Games object), you can listen with a higher priority and cancel the event.
Games.addEventListener(TransformGestureEvent.GESTURE_SWIPE, lrSwipe, false, 999); //the fourth parameter is the priority of the listener, when there are multiple event listeners for the same event, the listener with the higher number priority will be run first
function lrSwipe(e:TransformGestureEvent):void {
e.stopImmediatePropagation(); //this make the event stop and not trigger other listeners after this one
//...rest of your code
}
Again (as demonstrated in my answer to your other question), you're not going to want multiple listeners for a stage swipe event. With the code you've posted, when the user swipes over top of the Games screen, all three of your functions (lrSwipe, then downSwipe then onSwipe) will get called at the same time.