0

UPDATE

I want to implement this goal using XML if possible since I have too many 2 columned layouts. I don't know if the issue is using a LinearLayout (Just a guess) or something else. I plotted them by order (From Street -> Brgy -> City -> ZipCode etc) and that's why I am confused why it is not going in the right direction by what order I created them


just need some help with my XML/UI. I have a 2 column design of EditTexts and my goal is when I pressed next from keyboard in left side element, it will go to right side element then next to bottom left and so on (as per photo attachments at the bottom: From Street -> Brgy -> City -> ZipCode etc).

But I am having a problem when I press next, it goes down all the way. When I am on left side element, it goes bottom left side and same on right side element, it goes bottom right. How can I make a pattern as per my goal? Tried these but still, a problem occurs.

android:nexFocusRight="@+id/.."

and

android:nextFocusForward="@+id/.."

XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/TitleLayout1"
        android:layout_marginLeft="@dimen/marginSide1"
        android:layout_marginRight="@dimen/marginSide1"
        android:minHeight="25px"
        android:layout_marginTop="@dimen/marginTop2"
        android:background="@color/white">
        <LinearLayout
            android:orientation="horizontal"
            android:minWidth="25px"
            android:minHeight="20px"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/TitleBackround1"
            android:background="@color/bluegreendark"
            android:layout_gravity="center" />
        <TextView
            android:text="Personal Data"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:id="@+id/PDRN_Title1"
            android:background="@color/white"
            android:textColor="@color/darkgray"
            android:paddingLeft="@dimen/paddingSide1"
            android:paddingRight="@dimen/paddingSide1"
            android:layout_gravity="center"
            android:fontFamily="@string/fontFamily"
            android:textSize="@dimen/textSizeHeader" />
    </FrameLayout>
    <LinearLayout
        android:orientation="vertical"
        android:minWidth="25px"
        android:minHeight="25px"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/linearLayoutApplicant">
        <TextView
            android:text="Applicant"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColor="@color/lightgray"
            android:layout_marginLeft="@dimen/marginSide1"
            android:layout_marginTop="@dimen/marginSide1"
            android:fontFamily="@string/fontFamily"
            android:textStyle="bold" />
        <LinearLayout
            android:orientation="horizontal"
            android:layout_height="wrap_content"
            android:id="@+id/linearLayoutStreet"
            android:layout_marginLeft="@dimen/marginSide2"
            android:layout_marginRight="@dimen/marginSide2"
            android:weightSum="100"
            android:layout_width="match_parent">
            <EditText
                android:inputType="textPostalAddress"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:id="@+id/PD_Street"
                android:hint="Street"
                android:layout_weight="50"
                android:textColor="@color/darkgray"
                android:textSize="@dimen/textSizeCommon"
                android:fontFamily="@string/fontFamily"
                android:singleLine="true"
                android:nextFocusForward="@+id/PD_Baranggay" <!--Just tried it here-->
                android:nextFocusRight="@+id/PD_Baranggay"  <!--Just tried it here-->             
                android:maxLength="@string/genericLongLength" />
            <EditText
                android:inputType="textPostalAddress"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:id="@+id/PD_Baranggay"
                android:hint="Brgy"
                android:layout_weight="50"
                android:textColor="@color/darkgray"
                android:textSize="@dimen/textSizeCommon"
                android:fontFamily="@string/fontFamily"
                android:singleLine="true"
                android:maxLength="@string/genericLongLength" />
        </LinearLayout>
    </LinearLayout>
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/linearLayoutZipCode"
        android:layout_marginLeft="@dimen/marginSide2"
        android:layout_marginRight="@dimen/marginSide2"
        android:weightSum="100">
        <EditText
            android:inputType="textPostalAddress"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:id="@+id/PD_City"
            android:layout_weight="50"
            android:hint="City"
            android:textColor="@color/darkgray"
            android:textSize="@dimen/textSizeCommon"
            android:fontFamily="@string/fontFamily"
            android:singleLine="true"
            android:maxLength="@string/genericLength" />
        <EditText
            android:inputType="number"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:id="@+id/PD_ZipCode"
            android:layout_weight="50"
            android:hint="Zip Code"
            android:textColor="@color/darkgray"
            android:textSize="@dimen/textSizeCommon"
            android:fontFamily="@string/fontFamily"
            android:singleLine="true"
            android:maxLength="@string/yearLength" />
    </LinearLayout>
    <LinearLayout
        android:orientation="horizontal"
        android:layout_height="wrap_content"
        android:id="@+id/linearLayoutMobile"
        android:layout_marginLeft="@dimen/marginSide1"
        android:layout_marginRight="@dimen/marginSide1"
        android:weightSum="100"
        android:layout_width="match_parent">
        <EditText
            android:inputType="phone"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:id="@+id/PD_Telephone"
            android:hint="Telephone"
            android:layout_weight="50"
            android:textColor="@color/darkgray"
            android:textSize="@dimen/textSizeCommon"
            android:fontFamily="@string/fontFamily"
            android:singleLine="true"
            android:maxLength="@string/contactLength" />
        <EditText
            android:inputType="phone"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:id="@+id/PD_MobileNumber"
            android:hint="Mobile"
            android:layout_weight="50"
            android:textColor="@color/darkgray"
            android:textSize="@dimen/textSizeCommon"
            android:fontFamily="@string/fontFamily"
            android:singleLine="true"
            android:maxLength="@string/contactLength" />
    </LinearLayout>
    <LinearLayout
        android:orientation="horizontal"
        android:layout_height="wrap_content"
        android:id="@+id/linearLayoutOccularInspected"
        android:layout_marginLeft="@dimen/marginSide1"
        android:layout_marginRight="@dimen/marginSide1"
        android:weightSum="100"
        android:layout_width="match_parent">
        <EditText
            android:inputType="numberDecimal"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:id="@+id/PD_LengthOfStay"
            android:hint="Yrs of Stay"
            android:layout_weight="50"
            android:textColor="@color/darkgray"
            android:textSize="@dimen/textSizeCommon"
            android:fontFamily="@string/fontFamily"
            android:singleLine="true"
            android:maxLength="@string/numberDecimalLength" />
        <CheckBox
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:id="@+id/PD_OccularInspected"
            android:text="Occular Inspected"
            android:layout_weight="50"
            android:textColor="@color/darkgray"
            android:textSize="@dimen/textSizeCommon"
            android:fontFamily="@string/fontFamily" />
    </LinearLayout>
    <EditText
        android:inputType="textPostalAddress"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/PD_ProvincialAddress"
        android:hint="Provincial Address"
        android:layout_marginLeft="@dimen/marginSide1"
        android:layout_marginRight="@dimen/marginSide1"
        android:textColor="@color/darkgray"
        android:textSize="@dimen/textSizeCommon"
        android:fontFamily="@string/fontFamily"
        android:singleLine="true"
        android:maxLength="@string/addressLength" />
    <LinearLayout
        android:orientation="horizontal"
        android:layout_height="wrap_content"
        android:id="@+id/linearLayoutCivilStatus"
        android:layout_marginLeft="@dimen/marginSide1"
        android:layout_marginRight="@dimen/marginSide1"
        android:weightSum="100"
        android:layout_width="match_parent">
        <Spinner
            android:minWidth="25px"
            android:minHeight="25px"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/PD_CivilStatus"
            android:layout_weight="50"
            android:spinnerMode="dialog"
            style="@style/Widget.AppCompat.Spinner.Underlined"
            android:textSize="@dimen/textSizeCommon"
            android:fontFamily="@string/fontFamily"
            android:layout_marginTop="@dimen/marginNegativeTop2" />
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/PDRN_EditTextCivilStatusOthers"
            android:layout_weight="50"
            android:hint="Pls specify"
            android:textColor="@color/darkgray"
            android:textSize="@dimen/textSizeCommon"
            android:fontFamily="@string/fontFamily"
            android:visibility="gone"
            android:singleLine="true"
            android:maxLength="@string/otherLength" />
    </LinearLayout>
    <EditText
        android:inputType="number"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/marginSide1"
        android:layout_marginRight="@dimen/marginSide1"
        android:id="@+id/PD_NumberOfDependents"
        android:hint="No. of Dependents"
        android:textColor="@color/darkgray"
        android:textSize="@dimen/textSizeCommon"
        android:fontFamily="@string/fontFamily"
        android:singleLine="true"
        android:maxLength="@string/numberLength" />
    <LinearLayout
        android:orientation="horizontal"
        android:layout_height="wrap_content"
        android:id="@+id/linearLayoutSubjectNationality"
        android:layout_marginLeft="@dimen/marginSide1"
        android:layout_marginRight="@dimen/marginSide1"
        android:weightSum="100"
        android:layout_width="match_parent">
        <Spinner
            android:minWidth="25px"
            android:minHeight="25px"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="50"
            android:id="@+id/PD_SpinnerSubjectNationality"
            android:spinnerMode="dialog"
            style="@style/Widget.AppCompat.Spinner.Underlined"
            android:textSize="@dimen/textSizeCommon"
            android:fontFamily="@string/fontFamily"
            android:layout_marginTop="@dimen/marginNegativeTop2" />
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/PD_EditTextSubjectNationalityACR"
            android:hint="ACR No."
            android:layout_weight="50"
            android:textColor="@color/darkgray"
            android:textSize="@dimen/textSizeCommon"
            android:fontFamily="@string/fontFamily"
            android:visibility="gone"
            android:singleLine="true"
            android:maxLength="@string/genericLength" />
    </LinearLayout>
    <LinearLayout
        android:orientation="horizontal"
        android:layout_height="wrap_content"
        android:id="@+id/linearLayoutSpouseNationality"
        android:layout_marginLeft="@dimen/marginSide1"
        android:layout_marginRight="@dimen/marginSide1"
        android:weightSum="100"
        android:layout_width="match_parent">
        <Spinner
            android:minWidth="25px"
            android:minHeight="25px"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="50"
            android:id="@+id/PD_SpinnerSpouseNationality"
            android:spinnerMode="dialog"
            style="@style/Widget.AppCompat.Spinner.Underlined"
            android:textSize="@dimen/textSizeCommon"
            android:fontFamily="@string/fontFamily"
            android:layout_marginTop="@dimen/marginNegativeTop2" />
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/PD_EditTextSpouseNationalityACR"
            android:hint="ACR No."
            android:layout_weight="50"
            android:textColor="@color/darkgray"
            android:textSize="@dimen/textSizeCommon"
            android:fontFamily="@string/fontFamily"
            android:visibility="gone"
            android:singleLine="true"
            android:maxLength="@string/genericLength" />
    </LinearLayout>
</LinearLayout>

See photo attached

next1 next2

FreakyAli
  • 13,349
  • 3
  • 23
  • 63
jace
  • 1,634
  • 3
  • 14
  • 41
  • Hi @G.hakim . Your post seems have a copyright issue from this link stackoverflow.com/a/17990096/6914992 Sorry if it is a good answer but I can't accept for now. And also, I already read that before posting here and as per my answer, it is the code I tried to implement but with no effect. IMEoptions may be a good backup solution but I want to find ways using XML since I have too many codes with 2 columns. – jace Mar 05 '18 at 10:17
  • Possible duplicate of [Move to another EditText when Soft Keyboard Next is clicked on Android](https://stackoverflow.com/questions/17989733/move-to-another-edittext-when-soft-keyboard-next-is-clicked-on-android) – FreakyAli Mar 05 '18 at 11:13

1 Answers1

1

just add this to your EditText

android:imeOptions="actionNext"
android:nextFocusDown="@+id/yourNextEditText"

like this one.

<EditText
  android:inputType="textPostalAddress"
  android:layout_width="0dp"
  android:layout_height="wrap_content"
  android:id="@+id/PD_Street"
  android:hint="Street"
  android:layout_weight="50"
  android:textColor="@color/darkgray"
  android:textSize="@dimen/textSizeCommon"
  android:fontFamily="@string/fontFamily"
  android:singleLine="true"
  android:imeOptions="actionNext" <!--ADD THIS LINE -->
  android:nextFocusDown="@+id/PD_Barangay" <!--ADD THIS LINE -->
  android:nextFocusForward="@+id/PD_Baranggay" <!--REMOVE THIS LINE-->
  android:nextFocusRight="@+id/PD_Baranggay"  <!--REMOVE THIS LINE-->             
  android:maxLength="@string/genericLongLength" />

and do this in other EditText component that you need to have focus on pressing Next button.

Android Mediocre
  • 310
  • 3
  • 14
  • It really solved the problem . Thank you! But I am wondering why moveforward and moveright didn't solved the problem? or I really need imeOptions="actionNext" before it take actions although my keyboard has it's next button on the side – jace Mar 07 '18 at 03:25
  • I think it has a different function when you're using forward and right. You can remove the `imeiOptions` I thought you're having a different button on your lower right keyboard. Well nice to know that this help. Just add a little comment on your design. Try to expand the editText so the user can see more of their information rather than squeezing it. – Android Mediocre Mar 07 '18 at 03:32
  • I tried nextfocusdown without action next as imeoptions and it still works. This is still the answer by using nextFocusDown but we will only need actionNext if ever it is not present. It is present on my keyboard due to singleLine is set to true – jace Mar 07 '18 at 03:45
  • `singleLine` is deprecated i think. Try to use `maxLine="1"` – Android Mediocre Mar 07 '18 at 03:49
  • Thanks for the comment :) although I just followed the design of our designer that's why it is small . It denotes that it is under of something . – jace Mar 07 '18 at 03:51
  • I tried to use maxlines but next button is replaced by arrow next line so I have to use singleLine to achieve next button to appear – jace Mar 07 '18 at 04:34
  • that's why i add `imeiOptions` – Android Mediocre Mar 07 '18 at 05:21
  • actually I also tried maxLines + imeOptions but for some reason, next icon is not showing so I came up to singleLine = true as my solution :) – jace Mar 07 '18 at 06:24