Android - Multiple EditText in single TableRow
I have two EditText controls in one TableLayout>TableRow. I have another TableLayout>TableRow that has a single EditText control. When I hit "Enter" or "Next" from the first EditText field, the focus goes to the next table/row instead of the EditText field in the same TableRow. I've searched, but haven't had any luck finding an answer to this. How can I make the focus go to the next EditText field, instead of the EditText field in the next table?
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_width="fill_parent">
<TableRow
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:text="State"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2sp"
android:layout_marginRight="47dp"
android:padding="3dp"
android:textColor="@color/white"
android:textStyle="normal"
android:textSize="12dp">
</TextView>
<EditText
android:layout_height="30sp"
android:id="@+id/addeditServeeDetail_StateTextBox"
android:layout_width="50dp"
android:singleLine="true"
android:textSize="10sp"
android:maxLength="2" android:imeOptions="actionNext">
</EditText>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:text="Zip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2sp"
android:layout_marginRight="5dp"
android:layout_marginLeft="20dp"
android:padding="3dp"
android:textColor="@color/white"
android:textStyle="normal"
android:textSize="12dp">
</TextView>
<EditText
android:layout_height="30sp"
android:id="@+id/addeditServeeDetail_ZipTextBox"
android:layout_width="100dp"
android:singleLine="true"
android:textSize="10sp"
android:maxLength="10">
</EditText>
</TableRow>
</TableLayout>
<TableLayout
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_width="fill_parent">
<TableRow
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="2dp"
android:paddingTop="3dp">
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:text="County"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2sp"
android:layout_marginRight="35dp"
android:padding="3dp"
android:textColor="@color/white"
android:textStyle="normal"
android:textSize="12dp">
</TextView>
<EditText
android:layout_height="30sp"
android:id="@+开发者_StackOverflow中文版id/addeditServeeDetail_CountyTextBox"
android:layout_width="200dp"
android:singleLine="true"
android:textSize="10sp">
</EditText>
</TableRow>
</TableLayout>
If you need the focus to move from item to item in an exact order you need to specify that in the layout file.
See this: http://developer.android.com/guide/topics/ui/ui-events.html#HandlingFocus
android:nextFocusDown="@+id/YourNextEditText"
do it manually...:P
place an event which triggers when first edittext loses focus, in that event set focus to second edittext by using edittext.requestFocus() function.
use this event for focus in/out: editText.setOnFocusChangeListener();
精彩评论