Android requestFocus issue - android

I have a ViewFlipper with several LinearLayout with EditTexts; after pressing a button, there's some validation done, and should it fail, I need to set the focus to the Edit that needs to be modified. vf is the ViewFlipper; et123 is an EditText. When there's an error detected, the following is executed:
vf.setDisplayedChild(5);
findViewById(R.id.et123).requestFocus();
The funny thing is that the first time the button is pressed, the focus goes to another element in the right Layout. If I press the button one more time, the focus goes to et123.
Any ideas on why does it happen or how to fix it?
Thanks

You might need to call
findViewById(R.id.et123).setFocusableInTouchMode(true);
Before calling requestFocus() to enable receiving focus.

Related

Prevent losing focus on EditText when clicking on a button in Android

I'm writing a custom EditText that will have functionalities to bold/italic/underline/lists .... for Android
It's working so far so good but I've a problem that when a user clicking on a Button (for styling bold/italic...), the user will lose focus on the EditText.
Anyone has any ideas how to prevent the button taking focus from the EditText?
Thanks :)
The easiest thing to do would be to have the onClickListener of those buttons refocus the edit text as their last instruction.
You can also try putting focusable=false (and focusableInTouchMode=false) on the buttons. That may work, I'm not sure if focus is removed from the edit text when the screen is touched or when another item receives focus, which is subtly but important difference here. It would also slightly change any drawables on the button that use focused state.

Android Button Click not go through, but action still take place

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

What means this button state when my activity starts?

When my activity starts the button starts as below image, seems that it is selected.
button seems to be selected http://kodeinfo.com/wp-content/uploads/2014/03/post4_1.jpg
Button seems to be selected but I don't select it neither on activity nor layout.
I had checked and this is not related to focus. I tried starting the activity with requestFocus() on a button and does not have the same behavior.
Does anyone knows what is that? What is this state for the button? I don't want this behavior in my app, but I'm not being able to understand the issue in my code because I don't know what this state is.

Lose Focus when clicking actionbar button

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?

EditText does not lose focus after it gains it

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.

Categories

Resources