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:
android:nextFocusDown="@+id/.."
android:nextFocusLeft="@+id/.."
android:nextFocusRight="@+id/.."
android:nextFocusUp="@+id/.."
Besides directional navigation you can use tab navigation. For this you need to use
android:nextFocusForward="@+id/.."
To get a particular view to take focus, call
view.requestFocus()
To listen to certain changing focus events use a [`View.OnFocusChangeListener`][1]
----------
Keyboard button
----------
You can use [`android:imeOptions`][2] for handling that extra button on your keyboard.
> Additional features you can enable in an IME associated with an editor
> to improve the integration with your application. The constants here
> correspond to those defined by imeOptions.
The constants of imeOptions includes a variety of actions and flags, see the link above for their values.
**Value example**
[ActionNext][3] :
> the action key performs a "next" operation, taking the user to the
> next field that will accept text.
[ActionDone][4] :
> the action key performs a "done" operation, typically meaning there is nothing more to input and the IME will be closed.
**Code example:**
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="32dp"
android:layout_marginTop="16dp"
android:imeOptions="actionNext"
android:maxLines="1"
android:ems="10" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText1"
android:layout_below="@+id/editText1"
android:layout_marginTop="24dp"
android:imeOptions="actionDone"
android:maxLines="1"
android:ems="10" />
</RelativeLayout>
If you want to listen to imeoptions events use a [`TextView.OnEditorActionListener`][5].
editText.EditorAction +=HandleEditorAction;
private void HandleEditorAction(object sender TextView.EditorActionEventArgs e)
{
e.Handled = false;
if (e.ActionId == ImeAction.Send)
{
SendMessage();
e.handled = true;
}
}
----------
[1]: http://developer.android.com/reference/android/view/View.OnFocusChangeListener.html
[2]: http://developer.android.com/reference/android/widget/TextView.html#attr_android:imeOptions
[3]: http://developer.android.com/reference/android/view/inputmethod/EditorInfo.html#IME_ACTION_NEXT
[4]: http://developer.android.com/reference/android/view/inputmethod/EditorInfo.html#IME_MASK_ACTION
[5]: http://developer.android.com/reference/android/widget/TextView.OnEditorActionListener.html
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:
android:nextFocusDown="@+id/.."
android:nextFocusLeft="@+id/.."
android:nextFocusRight="@+id/.."
android:nextFocusUp="@+id/.."
Besides directional navigation you can use tab navigation. For this you need to use
android:nextFocusForward="@+id/.."
To get a particular view to take focus, call
view.requestFocus()
To listen to certain changing focus events use a [`View.OnFocusChangeListener`][1]
----------
Keyboard button
----------
You can use [`android:imeOptions`][2] for handling that extra button on your keyboard.
> Additional features you can enable in an IME associated with an editor
> to improve the integration with your application. The constants here
> correspond to those defined by imeOptions.
The constants of imeOptions includes a variety of actions and flags, see the link above for their values.
**Value example**
[ActionNext][3] :
> the action key performs a "next" operation, taking the user to the
> next field that will accept text.
[ActionDone][4] :
> the action key performs a "done" operation, typically meaning there is nothing more to input and the IME will be closed.
**Code example:**
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="32dp"
android:layout_marginTop="16dp"
android:imeOptions="actionNext"
android:maxLines="1"
android:ems="10" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText1"
android:layout_below="@+id/editText1"
android:layout_marginTop="24dp"
android:imeOptions="actionDone"
android:maxLines="1"
android:ems="10" />
</RelativeLayout>
If you want to listen to imeoptions events use a [`TextView.OnEditorActionListener`][5].
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
performSearch();
return true;
}
return false;
}
});
----------
[1]: http://developer.android.com/reference/android/view/View.OnFocusChangeListener.html
[2]: http://developer.android.com/reference/android/widget/TextView.html#attr_android:imeOptions
[3]: http://developer.android.com/reference/android/view/inputmethod/EditorInfo.html#IME_ACTION_NEXT
[4]: http://developer.android.com/reference/android/view/inputmethod/EditorInfo.html#IME_MASK_ACTION
[5]: http://developer.android.com/reference/android/widget/TextView.OnEditorActionListener.html