androidtablelayoutime

Problem using android:imeOptions="actionNext" in Table Layout


I've got this Table layout with 3 EditText fields & a button that performs a calculation.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent">
 <TextView
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="@string/lbl_fuel_order"
  android:textSize="18dp"
  android:gravity="center_horizontal"/>
 <TableLayout
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:layout_gravity="center"
  android:stretchColumns="*">
  <TableRow>
   <TextView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:text="@string/lbl_arr_kgs"
    android:textSize="12dp"
    android:layout_weight="1"/>
   <TextView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:text="@string/lbl_sg"
    android:textSize="12dp"
    android:layout_weight="1"/>
  </TableRow>
  <TableRow>
   <EditText
    android:id="@+id/arr_fuel"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:lines="1"
    android:inputType="number"
    android:imeOptions="actionNext"/>
   <EditText
    android:id="@+id/sg"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:lines="1"
    android:inputType="numberDecimal"
    android:imeOptions="actionNext"/>
  </TableRow> 
  <TableRow>
   <TextView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:text="@string/lbl_req_tanks_kgs"
    android:textSize="12dp"
    android:layout_weight="1"/>
  </TableRow>
  <TableRow>
   <EditText
    android:id="@+id/req_tanks_fuel"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:lines="1"
    android:inputType="number"
    android:imeOptions="actionNext"/>
   <Button
    android:id="@+id/btn_calc_fuel_order"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:text="@string/lbl_calc"/>
  </TableRow>
  <TableRow>
   <TextView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:text="@string/lbl_uplift_kgs"
    android:textSize="12dp"
    android:layout_weight="1"/>
   <TextView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:text="@string/lbl_uplift_l"
    android:textSize="12dp"
    android:layout_weight="1"/>
  </TableRow>
  <TableRow>
   <TextView
    android:id="@+id/req_weight"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:gravity="left"
    android:lines="1"
    android:text="000000"
    android:textSize="24dp"
    android:textColor="#ff0000"/>
   <TextView
    android:id="@+id/req_volume"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:gravity="left"
    android:lines="1"
    android:text="111111"
    android:textSize="24dp"
    android:textColor="#00ff00"/>
  </TableRow>
 </TableLayout>
    </LinearLayout>

The left-hand EditText, in the top row of the table layout, has focus when the activity starts. However, when I click next on the soft keyboard the cursor moves to the left-hand EditText in the bottom row rather than the EditText to the right (in the top row). I've tested the right-hand EditText, in the top row, which sends the cursor to the left-hand EditText in the bottom row as I would wish.

Is there any way of making the cursor go right from the left-hand EditText in the top row first & then from there to the left-hand EditText in the bottom row?

If that is possible, can I also arrange for it to then move focus to the button which is in the right-hand side of the bottom row?

Thanks


Solution

  • Try this...

    TextView nextField = (TextView)currentField.focusSearch(View.FOCUS_RIGHT);
    nextField.requestFocus();
    

    Android does search for the nearest available NEXT textfield to shift focus once you hit the NEXT button on the soft keyboard. You can specify the direction in which the search should be persuaded. You can also read about the IME(Input Method Editors) options