AutoCompleteTextView用于用户输入提示用户字符
1,先在主界面xml中定义好
<AutoCompleteTextView
android:layout_width="match_parent"
android:text="" android:layout_height="wrap_content" android:id="@+id/autocomplete_autoCompleteTextView"/>
2,然后再java中定义
AutoCompleteTextView m_autocomplete;
static final String[] COUNTRIES = new String[] { "Afghanistan", "Albania",
"Algeria", "American", "Andorra", "Angola", "Anguilla", "Antarctica"}
3,接着定义并创建用于实现及显示自动提示对话框的view界面
在layout下创建listview_item_array_layout.xml文件,并定义显示字符类型为TextView
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/listview_item_array_layout_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#ff0046"
android:textSize="20dip"
android:text=""/>
4,然后采用ArrayAdapter将layout,TextView ID和String[]相关联
m_autocomplete=(AutoCompleteTextView)findViewById(R.id.autocomplete_autoCompleteTextView);
ArrayAdapter<String> array=new ArrayAdapter<String>(this,R.layout.listview_item_array_layout,R.id.listview_item_array_layout_name,COUNTRIES);
m_autocomplete.setAdapter(array);
Android AutoCompleteTextView实现
最新推荐文章于 2021-05-26 05:58:54 发布