遇到一些问题与控制聚焦。下面我的接口定义具有:

源(RadioGroup中/可选) 目的地(EditText上) 量(的EditText) 转移(按钮)

我改变“源”的可见性我的代码。当时候,我不显示它,重点是自动转到我会想到是“目的地”,而不是“量”。我不知道我错过了什么。我怀疑这可能是一个Android的错误,我不知道。有没有人知道如何解决呢?

由于

<?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>
有帮助吗?

解决方案

这似乎是一个已知的问题。在谷歌代码下面柱为Android项目描述了同样的问题。

发行2705:上的EditText设置requestFocus的防止软键盘从开口

您可以尝试在布局在你的代码设置的重点,而不是。

其他提示

从在线文档

  

一个视图实际上不会取得焦点,如果它不是可聚焦(isFocusable()返回false),或者如果它是可聚焦的,它不是在触摸模式可聚焦(isFocusableInTouchMode()),而装置处于触摸模式。

我面临同样的问题, 试试这个代码为我工作。

             editText.post(new Runnable() {
                 public void run() {
                       editText.requestFocus(); 
                                   } 
                                           }); 

使用EditTextrequestFocus()方法。 :)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top