2011-08-07 36 views
0

我有一个活动,其中用户呈现的编辑文本列表。问题是,一旦活动开始,虚拟键盘就会立即显示在第一个编辑文本中。我不希望发生这种情况,因为在编辑文本之前有一个微调,而且我经常发现弹出键盘就会让用户忘记前一个微调。与EditText对象的Android问题

下面是相关代码:

<Spinner 
    android:id="@+id/event_location" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="30px" 
    android:prompt="@string/location_prompt" /> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Event Name: " /> 
<EditText 
    android:id="@+id/event_name" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" /> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Activity Type: " /> 
<Spinner 
    android:id="@+id/event_type" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" /> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Address: " /> 
<EditText 
    android:id="@+id/event_address" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" /> 

摘要:一个EditText活动开始,虚拟键盘会自动弹出。我不希望它这样做,除非用户按下编辑文本。

感谢您的任何帮助。

回答

2

的EditText上被自动设置为所以您需要放置android:focusable="false"editText.setFocusable(false)以防止在微调器可见时EditText被聚焦。您也可以尝试editText.setSelected(false)

1

试着改变你的微调XML这样的:

<Spinner 
android:layout_marginTop="30px" 
android:layout_height="wrap_content" 
android:layout_width="fill_parent" 
android:id="@+id/event_location" 
android:prompt="@string/location_prompt"> 
<requestFocus /> 
</Spinner> 

也可以尝试每个EditText上做:

android:focusable="false" 
android:focusableInTouchMode="false" 

看看这个帖子:Stop EditText from gaining focus at Activity startup

+0

好吗肯定,我会尝试了这一点。有没有办法让我可以做到这一点,以便没有任何提示?即在用户点击某物之前什么都不会弹出。 编辑 - requestFocus没有改变任何东西。 – JDS

+0

我编辑了我的答案,看到这些帮助。 – pqn

1

这是它的工作对我来说:

  1. 以确保编辑文本不会得到注重启动:
    在XML中设置的EditText的假的可聚焦属性:
android:focusable="false" 

2.为了使EditText在启动后再次可以被聚焦:
在代码中设置了可聚焦属性在setContent()方法之后想要的活动方法:

public void onCreate(Bundle icicle) { 
    super.onCreate(icicle); 

    setContentView(R.layout.main_view); 
    .... 

    EditText et = (EditText) findViewById(R.id.et_notes); 

    et.setFocusable(true); 

    et.setFocusableInTouchMode(true); 

    ... 
}