I've got a layout with two editexts. I need to set the second one focused and editable when the enter key is hit on the first one. I've got code for setting focus but I can't start typing when the second one gets the focus.
PS I also need edittext to be exactly one line height without possibility of making addtional rows. It works as well. pss android 2.3
XML code:
<EditText
android:id="@+id/email"
style="@style/profileLoginInput"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:hint="@string/email" android:ems="10" android:lines="1" android:maxLines="1" android:ellipsize="end">
<requestFocus />
</EditText>
<EditText
android:id="@+id/password"
style="@style/profileLoginInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:ems="10"
android:inputType="textPassword" android:hint="@string/password">
Java code :
((EditText) findViewById(R.id.email)).setOnKeyListener(new OnKeyListener(){
@Override
public boolean onKey(View v, int keyCode, KeyEvent event)
{
if (event.getAction() == KeyEvent.ACTION_DOWN)
{
switch (keyCode)
{
case KeyEvent.KEYCODE_DPAD_CENTER:
case KeyEvent.KEYCODE_ENTER:
((EditText) findViewById(R.id.password)).requestFocus();
return true;
default:
break;
}
}
return false;
}
});
setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { // TODO Auto-generated method stub if (edtPasscode3. getText(). length() == 1) edtPasscode4. requestFocus(); return false; } });
Make EditText non editable in Android To use this just set android:inputType="none" and it will become non editable.
In android, we can set the text of EditText control either while declaring it in Layout file or by using setText() method in Activity file.
Besides adding the + in front of id:
android:inputType="text"
android:nextFocusDown="@+id/..."
I also had to add:
android:imeOptions="actionNext"
android:inputType="text"
android:nextFocusDown="@+id/..."
worked for me
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With