Android - несколько EditText в одном TableRow - PullRequest
2 голосов
/ 23 сентября 2011

У меня есть два элемента управления EditText в одном TableLayout> TableRow. У меня есть другой TableLayout> TableRow, который имеет один элемент управления EditText. Когда я нажимаю «Enter» или «Next» в первом поле EditText, фокус переходит на следующую таблицу / строку вместо поля EditText в том же TableRow. Я искал, но мне не повезло найти ответ на этот вопрос. Как заставить фокус перейти к следующему полю EditText вместо поля EditText в следующей таблице?

            <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="@+id/addeditServeeDetail_CountyTextBox" 
                    android:layout_width="200dp"
                    android:singleLine="true" 
                    android:textSize="10sp">
                </EditText>

            </TableRow>

        </TableLayout>

Ответы [ 2 ]

3 голосов
/ 23 сентября 2011

Если вам нужен фокус для перемещения от элемента к элементу в точном порядке, вам нужно указать это в файле макета.

Смотрите это: http://developer.android.com/guide/topics/ui/ui-events.html#HandlingFocus

android:nextFocusDown="@+id/YourNextEditText"
0 голосов
/ 23 сентября 2011

сделать это вручную ...: P

поместите событие, которое срабатывает, когда первый текст редактирования теряет фокус, в этом событии установите фокус на второй текст редактирования, используя функцию edittext.requestFocus ().

используйте это событие для фокусировки вход / выход: editText.setOnFocusChangeListener (); * +1005 *

...