将焦点从一个布局中的一个 EditText 移动到另一个布局中的另一个 EditText
Move focus from one EditText in a layout to another EditText in another layout
我正在构建这个应用程序,我希望用户使用软键盘的“下一步”按钮更改 EditTexts 的焦点,如图所示
但它只是将第一列的焦点一直向下移动
我用了
android:nextFocussForward
使用所需的 EditText id 但它不起作用(nextfoucusleft/right/up/down 不起作用)
它包含父级垂直线性布局
每行都是水平线性布局
这里是 XML:
<LinearLayout
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"
android:orientation="vertical"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@color/header"
>
<TextView
android:text="@string/ecrit"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:textSize="@dimen/text_size_label"
android:textAlignment="center"/>
<TextView
android:text="@string/orale"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:textSize="@dimen/text_size_label"
android:layout_weight="1" />
<TextView
android:text="@string/lecture"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:textSize="@dimen/text_size_label"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/cells"
>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/ecrit1"
android:inputType="number"
android:maxLength="3"
/>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/orale1"
android:inputType="number"
android:maxLength="3"/>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/lecture1"
android:inputType="number"
android:maxLength="3"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/cells"
>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/ecrit2"
android:inputType="number"
android:maxLength="3"/>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/orale2"
android:inputType="number"
android:maxLength="3"
/>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/lecture2"
android:inputType="number"
android:maxLength="3"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/cells"
>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/ecrit3"
android:inputType="number"
android:maxLength="3"
android:nextFocusRight="@id/orale1"
android:nextFocusForward="@id/orale1"
android:nextFocusDown="@id/orale1"
android:nextFocusUp="@id/orale1"
android:nextFocusLeft="@id/orale1"
/>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/orale3"
android:inputType="number"
android:maxLength="3"/>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/lecture3"
android:inputType="number"
android:maxLength="3"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@color/result"
>
<TextView
android:paddingLeft="8dp"
android:text="@string/zero"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:textSize="@dimen/text_size_label"
android:textAlignment="center"/>
<TextView
android:paddingLeft="8dp"
android:text="@string/zero"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:textSize="@dimen/text_size_label"
android:layout_weight="1" />
<TextView
android:paddingLeft="8dp"
android:text="@string/zero"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:textSize="@dimen/text_size_label"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="15dp"
android:background="@color/header"
>
<TextView
android:text="@string/examen_ecrit"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:textSize="@dimen/text_size_label"
android:textAlignment="center"/>
<TextView
android:text="@string/examen_orale"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:textSize="@dimen/text_size_label"
android:layout_weight="1" />
<TextView
android:text="@string/examen_finale"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:textSize="@dimen/text_size_label"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/cells"
>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/ecritFinal"
android:inputType="number"
android:maxLength="3"/>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/oraleFinal"
android:inputType="number"
android:maxLength="3"/>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/finaleFinal"
android:inputType="number"
android:maxLength="3"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="15dp"
>
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:background="@color/header"
android:text="@string/classactivity"
android:textSize="@dimen/text_size_label"/>
<TextView
android:textSize="@dimen/text_size_label"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:background="@color/result"
android:text="@string/zero"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="15dp"
>
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:background="@color/header"
android:text="@string/finalgrade"
android:textSize="@dimen/text_size_label"/>
<TextView
android:textSize="@dimen/text_size_label"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:background="@color/result"
android:text="@string/zero"/>
</LinearLayout>
</LinearLayout>
尝试 android:imeAction = "actionNext"
和 android:nextFocussForward
。
我正在构建这个应用程序,我希望用户使用软键盘的“下一步”按钮更改 EditTexts 的焦点,如图所示 但它只是将第一列的焦点一直向下移动 我用了
android:nextFocussForward
使用所需的 EditText id 但它不起作用(nextfoucusleft/right/up/down 不起作用)
它包含父级垂直线性布局 每行都是水平线性布局
这里是 XML:
<LinearLayout
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"
android:orientation="vertical"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@color/header"
>
<TextView
android:text="@string/ecrit"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:textSize="@dimen/text_size_label"
android:textAlignment="center"/>
<TextView
android:text="@string/orale"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:textSize="@dimen/text_size_label"
android:layout_weight="1" />
<TextView
android:text="@string/lecture"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:textSize="@dimen/text_size_label"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/cells"
>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/ecrit1"
android:inputType="number"
android:maxLength="3"
/>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/orale1"
android:inputType="number"
android:maxLength="3"/>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/lecture1"
android:inputType="number"
android:maxLength="3"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/cells"
>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/ecrit2"
android:inputType="number"
android:maxLength="3"/>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/orale2"
android:inputType="number"
android:maxLength="3"
/>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/lecture2"
android:inputType="number"
android:maxLength="3"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/cells"
>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/ecrit3"
android:inputType="number"
android:maxLength="3"
android:nextFocusRight="@id/orale1"
android:nextFocusForward="@id/orale1"
android:nextFocusDown="@id/orale1"
android:nextFocusUp="@id/orale1"
android:nextFocusLeft="@id/orale1"
/>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/orale3"
android:inputType="number"
android:maxLength="3"/>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/lecture3"
android:inputType="number"
android:maxLength="3"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@color/result"
>
<TextView
android:paddingLeft="8dp"
android:text="@string/zero"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:textSize="@dimen/text_size_label"
android:textAlignment="center"/>
<TextView
android:paddingLeft="8dp"
android:text="@string/zero"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:textSize="@dimen/text_size_label"
android:layout_weight="1" />
<TextView
android:paddingLeft="8dp"
android:text="@string/zero"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:textSize="@dimen/text_size_label"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="15dp"
android:background="@color/header"
>
<TextView
android:text="@string/examen_ecrit"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:textSize="@dimen/text_size_label"
android:textAlignment="center"/>
<TextView
android:text="@string/examen_orale"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:textSize="@dimen/text_size_label"
android:layout_weight="1" />
<TextView
android:text="@string/examen_finale"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:textSize="@dimen/text_size_label"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/cells"
>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/ecritFinal"
android:inputType="number"
android:maxLength="3"/>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/oraleFinal"
android:inputType="number"
android:maxLength="3"/>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/finaleFinal"
android:inputType="number"
android:maxLength="3"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="15dp"
>
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:background="@color/header"
android:text="@string/classactivity"
android:textSize="@dimen/text_size_label"/>
<TextView
android:textSize="@dimen/text_size_label"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:background="@color/result"
android:text="@string/zero"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="15dp"
>
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:background="@color/header"
android:text="@string/finalgrade"
android:textSize="@dimen/text_size_label"/>
<TextView
android:textSize="@dimen/text_size_label"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:background="@color/result"
android:text="@string/zero"/>
</LinearLayout>
</LinearLayout>
尝试 android:imeAction = "actionNext"
和 android:nextFocussForward
。