AutoCompleteTextView在 输入数据时可以出现提
2020-03-10 本文已影响0人
android_Pie
//1.获得AutoCompleteTextView
AutoCompleteTextView at=(AutoCompleteTextView) findViewById(R.id.att);
at.setThreshold(1);//设置输入几个字符长度便于出现提示文本
//2.构建Adapter
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,
new String[]{"KK","JJJ","GGG","DDD","YYYY2020"});
//3.关联Adapter
at.setAdapter(adapter);
布局如下
<AutoCompleteTextView
android:id="@+id/att"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="please input" />