Seriously, nobody knows how to achieve this?. Is this even possible?. Maybe a yes or no answer could help me out!
I have a form that looks like this:
The rectangles with a B on it, means that are buttons. The other fields are Edit Texts and Text Views.
I want to be able to press the Tabulator keyboard and focus in this direction:
- 1st Name Edit text
- 2nd Company Edit text
- 3rd Button
- 4th Employee Edit text
- 5th Button
- 6th Date
- 7th Button
- 8th Time
- 9th Button
- 10th Description Edit text
- 11th Mark as done check box
- 12th save
- 13th clean
This is my Layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
style="@style/ContenedorPrincipal"
tools:context=".ClientsActivity" >
<TextView
android:id="@+id/textViewTask"
style="@style/FTitle"
android:text="@string/new_task" />
<!--____________________ Section: form, field: name task______________________________-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="3dp"
android:orientation="horizontal">
<TextView
android:id="@+id/textViewTaskName"
style="@style/FForm"
android:text="@string/name" />
<EditText
android:id="@+id/editTextTaskName"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="textCapSentences" >
</EditText>
</LinearLayout>
<!--______________________________ Section: form, fields: company,employee____________________-->
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="3dip"
android:stretchColumns="1,4" >
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textViewCompany"
style="@style/FForm"
android:text="@string/company" />
<AutoCompleteTextView
android:id="@+id/autocompleteCompany" />
<ImageButton
android:id="@+id/imageButtonWatchCompany"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/ic_menu_view"
android:contentDescription="@string/see_company"/>
<TextView
android:id="@+id/textViewEmployee"
style="@style/FForm"
android:text="@string/employee" />
<AutoCompleteTextView
android:id="@+id/autocompleteEmployee" />
<ImageButton
android:id="@+id/imageButtonWatchEmployee"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/ic_menu_view"
android:contentDescription="@string/see_employee"/>
</TableRow>
<!--____________________ Section: form, fields: date, time______________________________-->
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textViewDate"
style="@style/FForm"
android:text="@string/date" />
<Button
android:id="@+id/buttonDate" >
</Button>
<TextView />
<TextView
android:id="@+id/textViewTime"
style="@style/FForm"
android:text="@string/time" />
<Button
android:id="@+id/buttonTime">
</Button>
</TableRow>
</TableLayout>
<!--____________________ Section: form, field description ______________________________-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/textViewDescription"
style="@style/FForm"
android:text="@string/description" />
<EditText
android:id="@+id/editTextDescription"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:lines="5"
android:gravity="top|left"
android:scrollbars="vertical"
android:inputType="textMultiLine|textCapSentences"/>
</LinearLayout>
<CheckBox
android:id="@+id/checkBoxDone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/mark_as_done"/>
<!--____________________ Section: buttons: save and clean______________________________-->
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="3dip"
android:stretchColumns="0,1">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:ignore="UselessParent" >
<Button
android:id="@+id/buttonSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/save" />
<Button
android:id="@+id/buttonClean"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/clean" />
</TableRow>
</TableLayout>
Is there anyway to achive this?. Any help will be aprecciated.
SOLUTION
In the layout make sure to use android:imeOptions="actionNext":
<AutoCompleteTextView
android:id="@+id/autocompleteCompany"
android:imeOptions="actionNext" />
And programmatically in the onCreateView method, call to a personal method:
private void setUpFocus(View view){
etName.setNextFocusDownId(R.id.autocompleteCompany);
etCompany.setNextFocusDownId(R.id.imageButtonWatchCompany);
ImageButton button = (ImageButton) view.findViewById(R.id.imageButtonWatchCompany);
button.setFocusableInTouchMode(true);
}
With this part of the code, using tab key, I can go from name, then company, then first button, then employee.