I have 3 EditText
in a vertical sequence (header, main body, footer). The main EditText
in the middle must handle long text, while the other two just single-line EditText
.
I want the main EditText
to have "fling"/fast scrolling. To do so, I wrap it around a ScrollView
. This is working fine.
However, my problem is when a user hits the "Next" button in soft keyboard in the header EditText
(single-line, imeOption="actionNext"), the main EditText
does not receive the next focus (intead, the footer gets the focus).
If I remove the ScrollView
, then the next-focus is set correctly (but I cannot have the fling/fast scrolling anymore).
Here is my XML layout (there is no code in the activity):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<EditText
android:id="@+id/header"
android:singleLine="true"
android:imeOptions="actionNext"
android:text="Header!" android:layout_width="match_parent"
android:layout_alignParentTop="true"
android:nextFocusDown="@+id/main"
android:nextFocusForward="@+id/main"
android:layout_height="wrap_content" />
<ScrollView
android:id="@+id/scrollview"
android:layout_below="@+id/header"
android:layout_above="@+id/footer"
android:fillViewport="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/main"
android:text="Here we have some really long text"
android:layout_width="match_parent" android:gravity="top"
android:layout_height="wrap_content" />
</ScrollView>
<EditText
android:id="@+id/footer"
android:singleLine="true"
android:imeOptions="actionNext"
android:text="Footer!" android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:layout_height="wrap_content" />
</RelativeLayout>
you have to handle this in run time in the following manner.
EditText firstEditText=(EditText) findViewById(R.id.header);
final EditText mainEditText=(EditText) findViewById(R.id.main);
firstEditText.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId,
KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_NEXT) {
mainEditText.requestFocus();
return true;
}
return false;
}
});