I have two different main.xml files, one for portrait, one for layout. Each one has this code inside of a RelativeLayout inside of a Scrollview.
<LinearLayout
android:id="@+id/name_phone"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/acquire"
>
<EditText
android:id="@+id/name"
android:inputType="textPersonName"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="observer name"
android:nextFocusDown="@id/phone"
android:background="@android:drawable/editbox_background"
/>
<EditText
android:id="@+id/phone"
android:inputType="phone"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="phone number"
android:nextFocusDown="@id/phone"
android:background="@android:drawable/editbox_background"
/>
</LinearLayout>
etc ...
The oddity is this: as far as I know, you are not supposed to be able to refer to things that haven't happened yet in xml, so android:nextFocusDown="@id/phone" should fail because phone hasnt been declared; and that is what happens in my landscape xml but not in portrait. In portrait it works perfectly and passes the focus through all four EditTexts with no hitch. If I put the NextFocusDown into the landscape, it will fail to compile, stating "No resource found that matches the given name (at 'nextFocusDown' with value '@id/phone')."
A solution or explanation would be great. The idea is that I have four text boxes in two different LinearLayouts and whichever one has focus first will pass it to the EditText beneath it, skipping the others. I want it to work as I have it in portrait layout, when the user hits next on the name, focus moves to phone, when they hit next on that it moves to email, etc. I'm also curious as to why it is letting this work in portrait but not landscape.
This is a really old post but I'm answering it as best I can. From what I know you put the + sign the first time you are referencing the id, so on your:
android:nextFocusDown="@id/phone"
should actually be android:nextFocusDown="@+id/phone
because it is the first time you are referencing that object. Then take out the + sign where you have
android:id="@+id/phone"
Hope this helps anyone who comes across this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With