I have EditText widget on my activity.
How should I make/handle "commit" in that text field?
I saw that some applications control keyboard and there is "Done" or "Ok" key instead of "Enter". Maybe this is how should I do it... But I don't know how how to do it.
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).
I've got an Android application I'm writing. It has a ListActivity in it that's all set up to load my data using this layout for each item.
My data Adapter binds with no problem and I've set it up so that when an item is selected from the list this method is called.
private void showPasswordBox(View v) {
EditText passwordBox = (EditText)v.findViewById(R.id.hidden_box);
Button passwordSubmit = (Button)v.findViewById(R.id.hidden_box_submit);
passwordSubmit.setText("Login");
passwordSubmit.setVisibility(View.VISIBLE);
passwordBox.setFocusableInTouchMode(true);
passwordBox.setHint(R.string.password);
passwordBox.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
passwordBox.setVisibility(View.VISIBLE);
}
This has the effect of displaying and EditText and a Button (hidden_box and hidden_box_submit in my layout). Which is just what I wanted.
However a problem occurs when the user taps on the newly visible EditText (hidden_box). The IME pops up and hidden_box immediately loses focus. Consequently anything typed on the IME does not appear in the EditText. Instead it's doing this weird thing where anything typed appears above the keyboard in grey letters and remains at the bottom of the screen when the IME is dismissed. It's like the IME is typing into it's own temporary invisible box.
If the user taps on the EditText after the IME is already showing then the application behaves as it should. Anything typed on the IME appears in the EditText and remains when the IME is dismissed.
It seems to me that when the IME pops up (which it does immediately when the user taps on the EditText, as it should) it completely de-associates with my application and does its thing in IME la-la land unless I direct it to the EditText by tapping on the EditText before typing and dismissing the keyboard. How do I make it behave normally so it types directly into the EditText as soon as it pops up?
passwordBox.setFocusableInTouchMode(true);
Hope this will work. Does it?
In my Android application I want to add charecters while the user is entering the data. (ex:if user enters 'a' I want to show '(a' in EditText).
I believe this happens automatically. When the EditText gains focus, a connection is made between the edittext and the input manager. Basically anything that is entered via the input manager is then sent to the edittext. So just by clicking on the EditText on the screen and then typing, the letters should appear on their own.
Is there any way out for mapping the Done button to the button on the screen in Android. What I want is that I have one login screen user enters username and presses the next button on the soft keyboard which brings the focus on password field. AFter entering password when the user presses done button then the action which is performed on login button should be called.
Let me know if this is possible.
In your layout file, you can specify the focus order using attributes like nextFocusDown. If you have the focus order configured properly, hitting next should automatically take you to the next focusable element.
You can also add a KeyListener to the edit text to listen for the next key and set the focus accordingly.