EditText does not lose focus after it gains it - android

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.

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 - trigger adjustResize

I wrapped my form in a <ScrollView> and I set my manifest android:windowSoftInputMode="adjustResize" (default of react native). Now when I manually focus a field with my finger touch event, and the field is covered by keyboard, it successfully scrolls to the field I just pressed.
However, if I pragmatically focus the next field (refToTextInput.focus()), it is not scrolling to that next field (focus does happen). I need the scroll to happen.
How can I trigger the adjustResize again, so it scrolls into view the next field I focused?
Manual focus - good
Here is what happens on manual focusing the password field, screencast:
Programmatic focus - bad - fail
However if my focus is in the "username" field and then I do this.refToPassword.focus() on the onSubmitEditing of the username field. Focus moves to the password input, and the keyboard doesnt flash (this is perfect I don't want the keyboard to flash). HOWEVER, the scroll view doesn't scroll to this field. Here is screencast of programmatic focus:
This is not the exact solution that I am proposing. However, you might consider this as a workaround.
You might consider hiding the keyboard programatically and showing the keyboard again on requesting focus programatically in the next EditText field. So the complete pseudo code for requesting the focus in next field will be something like.
public void requestFocusToNextField(View view) {
view.requestFocus();
hideKeyboard();
showKeyboard();
}
Hope that helps!

Focus gain and lose by clicking on EditText in android

I have two edittext editextone and edittexttwo. Bydefault the edttextone should be focused then after when user click on edttexttwo then edttexttwo should get focus and edttextone will lose focus. now if user click on edttextone then edttextone should get focus and edttexttwo lose focus. please help me how can i achieve this.

Android: Detect When Soft Keyboard Is About to Show?

Is there a way to detect when the keyboard is about to be presented in Android?
My problem is that I have a ListView with EditTexts in it. When the keyboard is about to be presented, these are quite often redrawn, causing an EditText that was JUST tapped to lose focus and require an extra tap.
My proposed solution is to monitor when the keyboard is about to be shown, check to see which view currently has focus, then after the keyboard is done being shown, restore focus to that view.
However, I have no idea how to detect when the keyboard is "about to be shown" in Android. How would I do this?
(I would also accept an alternative answer that addresses my actual problem: EditText losing focus when keyboard is displayed)
You could do it the other way, create an unique OnFocusChangedListener myListener and set it to all your EditTexts and put a switch inside and store which is the last view getting/losing focus

PhoneGap + Android page doesn't refresh after soft keyboard closes

Most of the time (but not always), when I finish typing in a or and the soft keyboard hides, the view area is left raised with a black space on the bottom. Clicking, tilting or otherwise engaging the phone corrects the screen. However, user's first motion is usually pressing , but if you click submit it jumps down and you actually just click on the text area again. How do you stop this and get the screen to reset after the keyboard closes.
Take a look at you AndroidManifest.xml
http://developer.android.com/guide/topics/manifest/activity-element.html
I think you need to change android:configChanges.
I have the exact same problem what i did was handle hidekeyboard even in javascript and do something like window.scrollTo(0,0) or $("input[type=text],textarea").blur();
This will cause the the screen to get back to normal position
But there is just one problem when click from input field of type = text to a input field password it internally hide the keyboard which causes the hidekeyboard event to fire and scrolls the screen to top. This is the only side effect of this
Let me know if you find the solution for this

Categories

Resources