问题

我有一个Android Activity ,包含两个元素:

  1. EditText
  2. ListView

当我的 Activity 启动时, EditText 立即具有输入焦点(闪烁光标).我不想要任何控制在启动时有输入焦点.我试过:

EditText.setSelected(false);

没有运气.我如何说服 EditText Activity 开始时不选择自己?



解决方法

Luc和Mark的优秀答案,但缺少一个好的代码示例:

<!-- Dummy item to prevent AutoCompleteTextView from receiving focus -->
<LinearLayout
    android:focusable="true" 
    android:focusableInTouchMode="true"
    android:layout_width="0px" 
    android:layout_height="0px"/>

<!-- :nextFocusUp and :nextFocusLeft have been set to the id of this component
to prevent the dummy from receiving focus again -->
<AutoCompleteTextView android:id="@+id/autotext"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:nextFocusUp="@id/autotext" 
    android:nextFocusLeft="@id/autotext"/>



相关问题推荐