我在控制焦点方面遇到了一些问题。我的界面定义如下:
源(RadioGroup / 可选) 目的地(EditText) 数量(EditText) 传输(按钮)
我在代码中更改“源”的可见性。当我不显示它时,焦点自动转移到“数量”,而我希望它转移到“目的地”上。我不知道我错过了什么。我怀疑这可能是Android的一个bug,但我不确定。有人知道如何解决吗?
谢谢。
源(RadioGroup / 可选) 目的地(EditText) 数量(EditText) 传输(按钮)
我在代码中更改“源”的可见性。当我不显示它时,焦点自动转移到“数量”,而我希望它转移到“目的地”上。我不知道我错过了什么。我怀疑这可能是Android的一个bug,但我不确定。有人知道如何解决吗?
谢谢。
<?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">
<RadioGroup android:id="@+id/source"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone">
<RadioButton android:id="@+id/default"
android:checked="false"
android:text="@string/default"/>
</RadioGroup>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="1">
<TableRow>
<TextView
android:text="@string/destination"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textColor="#ffffff"
android:paddingRight="10sp"
android:layout_weight="1"/>
<EditText android:id="@+id/destination"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:singleLine="true"><requestFocus/></EditText>
</TableRow>
<TableRow>
<TextView
android:text="@string/quantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textColor="#ffffff"
android:paddingRight="10sp"
android:layout_weight="1"/>
<EditText android:id="@+id/quantity"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:singleLine="true"/>
</TableRow>
</TableLayout>
<Button android:id="@+id/transfer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/transfer"/>
</LinearLayout>
onResume
方法中添加EditText e = (EditText) findViewById(R.id.destination); e.requestFocus();
。 - Sebastian Roth