I have a common EditText. It's very strange because I can't focus it when use hard keyboard. Context condition:
switch Droid's hardkeyboard on
start the activity
click the editText to input
Fail to input. When you press any key, the editText lost focus.
To get focus:
press Dpad and you will see the focus starts from the 1st widget in the screen. And finally focus on the target EditText. Then you can input. Without this, you can't input with hard keyboard at all.
Soft keyboard doesn't have such focus problem.
I am using android 2.2. Is this a system bug?
As mentioned above this is clearly a bug with hard keyboard. If you have an EditText and a TabHost in your layout, on first key pressed, EditText lose focus and key press is sent to the activity instead. Here is a work around to this problem. Implement this in your activity.
#Override
public boolean onKeyDown(int keyCode, KeyEvent event){
final EditText myInputField = (EditText) findViewById(R.id.MyInputEditText);
// this will happen on first key pressed on hard-keyboard only. Once myInputField
// gets the focus again, it will automatically receive further key presses.
if (!myInputField.hasFocus()){
myInputField.requestFocus();
myInputField.onKeyDown(keyCode, event);
}
return super.onKeyDown(keyCode, event);
}
if you have multiple EditText fields, you will need to keep track of currently focused EditText in a class variable and use it in onKeyDown method.
I have the same problem. I kinda agree with Jay. Typically TabHost, and/or TabActivity utilize a LocalActivityManager that keeps track of embedded Activities or appropriate ContentStrategy component that is displayed within the FrameLayout element. In simple words, this is a typical embedded Activities/ embedded Views layout problem. The Edit Text is on the top-most Activity/View that is taking the touch-screen space, while there's a core Activity that is actually hosting this Activity/View that probably is grabbing the InputMethodService focus and keeping it away from the Edit Text, only for the hard-keyboard scenario. The soft-keyboard just works fine.
One change I did to my Edit Text is to change the InputType as purely decimal. So when the Edit Text gains focus, the soft keyboard shows a numeric key-pad and not the alphabetical qwerty key-pad. I ran it on a Motorla Droid Pro emulator, that I updated in Eclipse Plugins from the Motodev website. Apparently, when I try to enter text from the hard keyboard after having given focus for the Edit Text (and the soft-keyboard is showing a numeric key-pad), after I click 'ALT + 2', the soft-keyboard is reloaded as alphabetic key-pad while the Edit Text loses focus entirely.
Seems like a serious bug to me in the Froyo release, insufficient support for hard-keyboard devices for edit text views in layouts (LinearLayout) that are embedded in other layouts (FrameLayout of a TabHost).
Related
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!
Previously I had a problem to do with soft keyboard backspace on Android 4.4.3 and this only occurs on the device that uses the Android Keyboard (AOSP).
Backspace seems to not work when the view is currently in focus on a text box and when I tap on the right of the entered text in the text box, sometime backspace becomes disabled and you can't get it to work without having to refocus on the text box again.
But I seem to fix the issue by overriding the deleteSurroundingText() in my CustomInputConnection class as suggested in this post (Android: Backspace in WebView/BaseInputConnection) However, I discovered a problem which is caused by overriding the onCreateInputConnection method in the WebView, for some reason when putting focus on to an element with an input type set to number, it displays a Qwerty Keyboard rather than a number keyboard.
Any suggestions to why this is happening is much appreciated.
In Android if we press ?123 key (or similar) on software keyboard it shows us digits/symbols layout. And it will automatically turns back to alphabetical layout when whitespace pressed or EditText cleared by app from code.
Is there any option to turn off this "auto reset" behavior? Maybe some flag for EditText, InputConnection, InputType, etc.
Note that numeric keyboard is not suitable. It must be common keyboard (InputType.TYPE_CLASS_TEXT) which just allows only manual switching between layouts.
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
I'd like to highlight the text in an EditText when a keyboard opens for user input (this could be a hardware keyboard or the virtual keyboard).
Highlighting isn't my problem, my problem is a trigger to highlight. Is there a handler that gets executed when the keyboard appears on a specific View (in this case, my EditText)? Are there different handlers for hardware keyboard vs virtual keyboard?
As far as I know, you can't get notified of those things at that level. Why not just highlight it when the EditText gets focus? In practice this will generally mean that an IME is displayed.
In fact, there is already a method to do exactly this: setSelectAllOnFocus.