In my XML layout, I have among other things two EditText elements and a few buttons. XML looks like this (most things removed, only relevant pieces left)
<RelativeLayout>
<RelativeLayout android:id="@+id/entry_id">
<Button
android:id="@+id/btn_select"
layout_alignParentRight="true" />
<EditText
android:id="@+id/txt_id"
android:layout_toLeftOf="@id/btn_select"
anddroid:nextFocusDown="@id/txt_extras" />
<Button
android:id="@+id/btn_quality"
android:layout_below="txt_id" />
</RelativeLayout>
<EditText
android:id="@+id/txt_extras"
android:layout_below="@id/entry_id" />
</RelativeLayout>
This produces a layout sort of like this:
+-----------------------------------------------+
|+---------------------------------------------+|
|| ||
|| +----------------------+ +-------------+ ||
|| | First text field | | Button | ||
|| +----------------------+ +-------------+ ||
|| ||
|| +----------------+ ||
|| | Another button | ||
|| +----------------+ ||
|| ||
|+---------------------------------------------+|
| |
| +-------------------------------------------+ |
| | Second text field | |
| +-------------------------------------------+ |
+-----------------------------------------------+
Note that this is not the entire layout, there are a lot more different views in it, but I’m only concerned with these ones. The reason RelativeLayouts are used is because they actually make it possible to lay out views in the way that the client wants.
Now, I need to define the block with the first text and buttons before defining the second text so that I could specify that the second text is below that block. However then I get an error in the first text field because I’m referring to the second text field in the nextFocusDown attribute, because the second text field is not defined yet. This becomes catch 22. Is there any way to make eclipse/lint/whatever understand that the field it’s complaining about not being there is actually there, just a few lines below? That is, is it possible to make it look at the file holistically, as a whole, and not line-by-line?
Alternatively, is there any other way to specify that I want the focus to go to the second text field and not to the second button when “next” is pressed on the soft keyboard?
The above line should be changed to:
As you can see in the input events documentation, they use
@+idfornextFocus*, even if the ID is already defined.If you still get an error, you may have to change
android:id="@+id/txt_extras"toandroid:id="@id/txt_extras"(removing the+sign), but this shouldn’t be necessary.