In my activity I would like to vibrate if I click once on a button, and do something else (for example closing the window with the button "close") if I click twice on it. I'm thinking of measuring the time between 2 clicks on a button and if it's less than a given intervall, then doing the given function, but I don't know how can I do that, and it may be too complicated.
I implemented the OnFocusChangeListener of the button after setting Focusable to false, and it can vibrate, but I don't have the solution of double click.
Try to use onDoubleTapListener.
Here are examples:
http://android-journey.blogspot.com/2010/01/android-gestures.html
Related
Sorry if the title makes no sense. What I'm trying to accomplish is to be able to long click a button, and once the long click is detected, to keep on doing a certain task.
To put it into context, I have a view with a background that changes to a random color on click. I would like to have the background keep on changing color as long as I long click the button. So, basically, upon long click and keeping the button pressed, the background will keep on changing.
Thank you very much folks :)
This isn't possible with view.setOnLongClickListener() because an OnLongClickListener has a very specific way of functioning. As soon as enough time has passed, the listener will activate and the code is run.
What you want is to use view.setOnTouchListener(). This way you can set a Timer when it detects a MotionEvent.ACTION_DOWN. Once the timer is long enough to equal a long click, you can have it trigger your color changing code repeatedly until the OnTouchListener detects a MotionEvent.ACTION_UP. That's when you can stop the color changing code.
I want when a button is pressed in my activity, for the click not to occur (such as clickEnabled being false) but I want the action that would have occurred to still happen.
For example, say I have a Dialer application:
When button "One" is pressed, the user will not see that the button was actually clicked, but the action of adding a 1 to the edittext will still occur. Thank you for your help!
I think you can make a selector as your button's background.and most important is samecolor no matter that is click , touch or idle . So through this ,you fake a no click effect.
And same time ,you can also add a click listener to this button to get the click event.
Hope that give you some suggestion.
I think you should simply use onTouchListener event for buttons instead of onclickListener
Hi there is thery any way to invoke a method that enables or disables the Touch Screen of Android?
I want this, because I have several buttons on my activity. When the user clicks on a button, it takes a few seconds to start the following activity, and because of that, while waiting that time, I don't want the user to be able to press anything.
I used a boolean that is True at start, then It changes to false when I click on the first button. And to every click on a button I check if the boolean is true...
But the problem is that Visually the user can click the button, it gets that look of being pressed..
So is there any good method that disables the entire touch screen ? And another that enables the entire touch screen ?
Thanks alot in advance ;)
But the problem is that Visually the user can click the button, it gets that look of being pressed
Disable the buttons, using setEnabled(false). This will not only prevent the user from clicking on them, but they will visually appear disabled, to let the user know that the user cannot click on them. It is important for the user to get the proper visual feedback about the buttons being disabled (and later enabled).
is thery any way to invoke a method that enables or disables the Touch Screen of Android?
Not really.
Consider an activity with a few buttons.
We can dynamically assign the focus this way:
b1.requestFocus();
If the user double taps the button, I want force a loss of focus.
How could I do that?
The trick is to detect a double tap. One way is to start a timer on the first tap, and check whether the same button is tapped again within the timeout value.
You can lose focus by setting setFocusable to false.
I have created a button. Now I want to do:
A single click of a button will open a dialog.
Double click of a button will open a dial pad.
OnLongtouchpress of buttons I want to change the color of the button.
Now in my case, I have used a single click event. So I want to know is there any option for double click and onlongtouchpress event on the same button if so, please suggest to me. With examples, if it is possible.
Regards
Anshuman
Use button.setOnLongClickListener to handle onLongclick event
For double click event See the followig URL
http://mobile.tutsplus.com/tutorials/android/android-gesture/
You need to set specify listeners.
Button btn = (Button)findVieByID(R.id.button1);
btn.setOnClickListener(.....);
btn.setOnLongClickListener(.....);
setOnDoubleTapListener not existing for Button