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.
Related
I have an idea on how to implement it, but wondering whether it would be an optimal solution.
So I want to save the user input in variable and pass it to a dialog in editText's textChanged listener event. Would it be an optimal solution?
I have implemented a listener : onFocusChanged to insert values in db when a edittext lose focus.
The thing is when I click the Send button (in action bar), it first do the action, and then it triggers a last onFocusChanged.
It should first lose the focus, and then execute the action?
Can anybody explain me that?
The solution should be giving focus to another button that is not edittext, but I just have a actionbar button, and it seems difficult giving it the focus.
Any suggestion will be appreciated !
I suspect that tapping the Send button isn't changing the focus at all (it is probably a nonfocusable view). What does your send operation do? Is there something at the end of Send which might be setting focus to some other view?
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.
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
At first my EditText had the focus as soon as the app loaded the screen and I disabled that with
android:focusable="true"
android:focusableInTouchMode="true"
However, there is no way to lose focus after clicking the EditText. The focus is still there when I try to click outside of the text area. This also happens when I click on the EditText to change the value and press "Done" on the on screen keyboard. Does anyone know a way for me to accomplish this?
Focus only changes if you click on something else that can gain focus. Issue is: If you click on a button for instance you might not lose focus, unless you do what Mathew said. Problem with that is: A button whose focusableInTouchMode is set to "true", needs now to be clicked TWICE: Once for gaining focus and once for performing OnClick. A nagging issue, that was haunting me as well right now.