初识AutoCompleteTextView

AutoCompleteTextView自动补全框继承自TextView和EditView,通过一个下拉框的形式可以补全信息。

可以通过setThreshold()方法指定用户输入多少个字符后开始显示携带建议信息的下拉框。

        <AutoCompleteTextView
            android:id="@+id/autoCompleteTextView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:text="AutoCompleteTextView" />

设置数据源并添加适配器

 1 private void showAutoCompleteTextView() {
 2         
 3         autoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
 4         /*建立数据源
 5         建立adapter并绑定数据源
 6         绑定adapter到UI
 7         */
 8         String[] countriesStrings = getResources().getStringArray(R.array.countries_array);
 9         ArrayAdapter<String> countryListAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line,countriesStrings);
10         autoCompleteTextView.setAdapter(countryListAdapter);
11     }

 

posted @ 2014-12-26 02:36  iRac  阅读(146)  评论(0编辑  收藏  举报