RecyclerView中的EditText处理导航

问题描述 投票:1回答:1

我已将以下布局作为我的recyclerview的行布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
    <TextView
            android:id="@+id/tv_title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="@dimen/dimen_15"
            android:textColor="@color/colorBlack"
            android:textSize="@dimen/font_dimen_16"
            app:font_type="regular"
            tools:text="day" />
    <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:orientation="horizontal">
        <EditText
                android:id="@+id/edt_rs"
                style="@style/edt_rounded_style"
                android:hint="@string/str_rs"
                android:imeOptions="actionDone" />
        <EditText
                android:id="@+id/edt_discounted_price"
                style="@style/edt_rounded_style"
                android:hint="@string/str_discounted_price"
                android:imeOptions="actionDone" />
    </LinearLayout>
    <View
            android:layout_width="match_parent"
            android:layout_height="@dimen/dimen_0p1"
            android:layout_marginTop="@dimen/dimen_5"
            android:layout_marginBottom="@dimen/dimen_5"
            android:background="@color/colorGrey" />
</LinearLayout>

现在,您可以如上所示,在Recyclerview的单行中有两个EditText。

我接下来必须从一个EditText移至另一个:水平然后垂直。

例如,如果我在第一个edittext中写了一些东西,然后在软键盘上单击NEXT,则同一行中的第二个EditText应该获得焦点。

以同样的方式,当我在同一行中为第二个EditText输入完值然后单击NEXT时,下一行中的下一个edittext应该得到关注。

这是RecyclerView中EdiTexts之间导航的问题。

我该如何实现?

谢谢。

android kotlin android-recyclerview android-edittext recycler-adapter
1个回答
1
投票

使用edittext中的FocusDown标记进行导航

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
<TextView
        android:id="@+id/tv_per_title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="@dimen/dimen_15"
        android:textColor="@color/colorBlack"
        android:textSize="@dimen/font_dimen_16"
        app:font_type="regular"
        tools:text="Per day" />
<LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:orientation="horizontal">
    <EditText
            android:id="@+id/edt_rs"
            android:nextFocusDown="@id/edt_discounted_price"
            style="@style/edt_rounded_gym_fees_style"
            android:hint="@string/str_rs"
            android:imeOptions="actionDone" />
    <EditText
            android:id="@+id/edt_discounted_price"
            style="@style/edt_rounded_gym_fees_style"
            android:hint="@string/str_discounted_price"
            android:imeOptions="actionDone" />
</LinearLayout>
<View
        android:layout_width="match_parent"
        android:layout_height="@dimen/dimen_0p1"
        android:layout_marginTop="@dimen/dimen_5"
        android:layout_marginBottom="@dimen/dimen_5"
        android:background="@color/colorGrey" />

© www.soinside.com 2019 - 2024. All rights reserved.