1

我有这个表格布局,其中包含 3 个 EditText 字段和一个执行计算的按钮。

<?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>

活动开始时,表格布局顶行中的左侧 EditText 具有焦点。但是,当我在软键盘上单击下一步时,光标会移动到底行左侧的 EditText,而不是右侧(顶行)的 EditText。我已经测试了顶行中的右侧 EditText,它按照我的意愿将光标发送到底行的左侧 EditText。

有没有办法让光标首先从顶行的左侧 EditText 向右移动,然后从那里移动到底行的左侧 EditText?

如果可能的话,我还可以安排它然后将焦点移到底行右侧的按钮上吗?

谢谢

4

3 回答 3

2

试试这个...

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

一旦您点击软键盘上的 NEXT 按钮,Android 会搜索最近的可用 NEXT 文本字段以转移焦点。您可以指定应该说服搜索的方向。您还可以阅读有关IME(输入法编辑器)选项的信息

于 2011-02-14T18:20:15.853 回答
0

只需将 android:singleLine="true" 添加到您的 EditText。它会工作的!:)

于 2014-06-06T15:17:20.560 回答
0

在我的情况下添加android:lines="1"帮助。EditText

android:singleLine="true",正如另一个答案所建议的那样,自 API 级别 15 以来已弃用。

于 2021-04-25T13:06:35.550 回答