简体   繁体   中英

Android: Next EditText focus with different views doesn't work properly

I have this widget:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/root"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/white"
    android:foreground="?attr/selectableItemBackground">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:orientation="horizontal"
        android:padding="@dimen/keyline_1">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical">

            <LinearLayout
                android:id="@+id/title_layout"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/title"
                    style="@style/WizardItemTitleView"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:maxLines="1"
                    android:singleLine="true"/>

                <TextView
                    android:id="@+id/subtitle"
                    android:textColor="@color/amber_200"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:visibility="gone"/>

            </LinearLayout>

            <LinearLayout
                android:id="@+id/info_layout"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_toRightOf="@+id/title_layout"
                android:layout_marginLeft="@dimen/keyline_1"
                android:gravity="right"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true">

                <EditText
                    android:id="@+id/edit"
                    style="@style/WizardItemEditTextView"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="left"
                    android:maxLines="1"
                    android:singleLine="true"/>                       

            </LinearLayout>

        </RelativeLayout>

    </LinearLayout>

</FrameLayout>

This is my test layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <com.example.anthony.myapplication.wizard.ItemWizardEditTextView
        android:id="@+id/name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:title="NOM"/>

    <com.example.anthony.myapplication.wizard.ItemWizardEditTextView
        android:id="@+id/brand1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:title="MARQUE 1"/>

    <com.example.anthony.myapplication.wizard.ItemWizardEditTextView
        android:id="@+id/brand2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:title="MARQUE 2"/>

    <com.example.anthony.myapplication.wizard.ItemWizardEditTextView
        android:id="@+id/brand3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:title="MARQUE 3"/>

</LinearLayout>

So if I set by default @+id/name edittext with a default value, then the next action can't perform on my next EditText. I don't know where is the focus.

Thank you very much for your help!

if you want focus on any of the edittext use

<requestfocus />

and its good to use visibility programmaticaly

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM