15.文本提示框

安卓提示文本框AutoComplete

简而言之,创建一个提示文本框,在为我们的提示文本框通过适配器配置提示的数据
xml代码
<AutoCompleteTextView
    android:id="@+id/au_1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textColor="#000"
    android:hint="你好,请输入名字"
    />

提示文本框像上面那样新建就可以了,
既然是提示文本框就需要有提示的内容,
内容我们用到了数据适配器为自动提示文本框提供信息。

//只做一个数组用来放补全文本框的数据
private String[] num = new String[]{"10086","10010","12306","夏小二","尹小六"};
    //自动补全文本框,
    final AutoCompleteTextView auto = (AutoCompleteTextView)findViewById(R.id.au_1);

    //使用的是android里面自己带的一个布局文件
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, 
        android.R.layout.simple_dropdown_item_1line,num);

    //给补全文本框匹配内容,内容被我们放在了适配器里面
    auto.setAdapter(adapter);

猜你喜欢

转载自www.cnblogs.com/gzyx/p/11775124.html
今日推荐