Search code examples
androidandroid-edittextsearchview

edittext nextfocusdown to searchview


I'm developing an android mobile app, which contains a list if EditTexts.

One of them is a SearchView and it looks like this (4th row is the SearchView):

enter image description here

In this part of program I have to move from one to another EditTextusing "Next" button on keyboard.

I have a problem when requesting focus from 3d to 4th row. When i tap "Next", it goes from 3d to 5th row and pass SearchView. I'm using android:nextFocusDown="myid" for this.

Here is a code snippet:

...
           <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/main_margin"
                android:layout_marginRight="@dimen/main_margin">

                <com.google.android.material.textfield.TextInputLayout
                    android:id="@+id/textInputMiddleName"
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/fields_height"
                    android:layout_alignParentStart="true"
                    android:layout_centerHorizontal="true"
                    android:padding="@dimen/space_textinput"
                    app:boxBackgroundMode="none">

                    <ru.meteor.citykrepost.helpers.AdvancedEditText
                        android:id="@+id/textInputEditTextMiddleName"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="@null"
                        android:hint="@string/middle_name"
                        android:nextFocusDown="@id/searchViewBuilding"
                        android:singleLine="true"
                        android:textSize="@dimen/text_normal_size" />
                </com.google.android.material.textfield.TextInputLayout>

                <ImageView
                    android:id="@+id/middleNameError"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentEnd="true"
                    android:layout_centerVertical="true"
                    android:layout_gravity="center_vertical"
                    android:contentDescription="@string/middle_name"
                    android:src="@drawable/background_error"
                    android:visibility="invisible" />
            </RelativeLayout>

            <View
                android:layout_width="match_parent"
                android:layout_height="@dimen/slider_height"
                android:background="@android:color/white" />

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/main_margin"
                android:layout_marginRight="@dimen/main_margin">

                <ru.meteor.citykrepost.helpers.AdvancedSearchView
                    android:id="@+id/searchViewBuilding"
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/fields_height"
                    android:layout_marginStart="@dimen/search_view_padding_left"
                    android:imeOptions="actionNext"
                    android:nextFocusDown="@id/textInputEditTextFlat"
                    android:focusable="true"
                    android:padding="@dimen/space_textinput"
                    android:theme="@style/MySearchViewStyle"
                    app:iconifiedByDefault="false"
                    app:queryHint="@string/street"
                    app:searchHintIcon="@null"
                    app:searchIcon="@null" />

                <ImageView
                    android:id="@+id/addressError"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentEnd="true"
                    android:layout_centerVertical="true"
                    android:layout_gravity="center_vertical"
                    android:contentDescription="@string/address_title"
                    android:src="@drawable/background_error"
                    android:visibility="invisible" />
            </RelativeLayout>
...

What could be wrong with this? Any help would be appreciated.


Solution

  • Use android:imeOptions="actionNext" inside your AdvancedEditText view. Good luck.