抢断的EditText焦点 [英] EditText steals focus

查看:137
本文介绍了抢断的EditText焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个活动,它有一个EditText和一个ListView。所述的EditText可用于过滤列表视图的行

问题是,当活动的负载,默认情况下键盘弹出窗口。我想,该键盘上来只有当用户actualy水龙头在文本框中,默认情况下。

 公共无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);    的setContentView(R.layout.filterablelayout);    filterText =(EditText上)findViewById(R.id.search_box);
    filterText.addTextChangedListener(filterTextWatcher);    filterText.setVisibility(View.INVISIBLE);    GetCategories();
}

我的布局XML是如下:

 < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:方向=垂直><的TextView
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:文字=@字符串/ selectcat/><的EditText
    机器人:ID =@ + ID / search_box
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:提示=@字符串/ categorytxthint
    安卓的inputType =TEXT
    机器人:MAXLINES =1/>< ListView控件
    机器人:ID =@机器人:ID /列表
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =0dip
    机器人:layout_weight =1/>< / LinearLayout中>


解决方案

在清单,把你的活动如下:

 的android:windowSoftInputMode =stateHidden

I have an Activity, which has an EditText and a ListView. The EditText can be used to filter listview rows.

problem is that when the Activity loads up, the keyboard popups by default. I would want that the keyboard come up only when a user actualy taps into the text box and not by default.

Public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.filterablelayout);

    filterText = (EditText) findViewById(R.id.search_box);
    filterText.addTextChangedListener(filterTextWatcher);

    filterText.setVisibility(View.INVISIBLE);

    GetCategories();
}

My layout xml is as below:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/selectcat" />

<EditText
    android:id="@+id/search_box"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:hint="@string/categorytxthint"
    android:inputType="text"
    android:maxLines="1" />

<ListView
    android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="0dip"
    android:layout_weight="1" />

</LinearLayout>

解决方案

In the manifest, put the following for your activity :

android:windowSoftInputMode="stateHidden"

这篇关于抢断的EditText焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆