When I press the 'Next', the focus on the User EditText must be move to the Password. Then, from Password, it must move to the right and so on. Can you help me on how to code it?
<LinearLayout
android:id="@+id/LinearLayout01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User Name*" />
<EditText
android:id="@+id/txt_User"
android:layout_width="290dp"
android:layout_height="33dp"
android:singleLine="true" />
</LinearLayout>
<LinearLayout
android:id="@+id/LinearLayout02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password*" />
<EditText
android:id="@+id/txt_Password"
android:layout_width="290dp"
android:layout_height="33dp"
android:singleLine="true"
android:password="true" />
<TextView
android:id="@+id/confirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password*" />
<EditText
android:id="@+id/txt_Confirm"
android:layout_width="290dp"
android:layout_height="33dp"
android:singleLine="true"
android:password="true" />
</LinearLayout>
In your onEditorAction handler, keep in mind that you must return a boolean that indicates if you are handling the action (true) or if you applied some logic and want the normal behaviour (false), as in the following example:
I found this when I returned true after performing my logic since focus did not move.
Focus Handling
Focus movement is based on an algorithm which finds the nearest neighbor in a given direction. In rare cases, the default algorithm may not match the intended behavior of the developer.
Change default behaviour of directional navigation by using following XML attributes:
Besides directional navigation you can use tab navigation. For this you need to use
To get a particular view to take focus, call
To listen to certain changing focus events use a
View.OnFocusChangeListener
Keyboard button
You can use
android:imeOptions
for handling that extra button on your keyboard.The constants of imeOptions includes a variety of actions and flags, see the link above for their values.
Value example
ActionNext :
ActionDone :
Code example:
If you want to listen to imeoptions events use a
TextView.OnEditorActionListener
.Use the following line
parentedit
is the ID of the nextEditText
to be focused.The above line will also need the following line.
or
Thanks for the suggestion @Alexei Khlebnikov.
just use the following code it will work fine and use inputType for every edittext and the next button will appear in keyboard.
should bring the same effect. After hiting next to bring the focus to the next element.
use this in addition if you dont want the next view to get the focus