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;
}
});