自动提示文本框:
AutoCompleteTextView(单一提示)
android:completionThreshold=”1”
activity_main.xml类:
<AutoCompleteTextView
android:id="@+id/act_main_cat1"
android:layout_width="match_parent"
android:layout_height="60dp" />
在layout创一个类:名为act_main_item1:
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:textColor="@color/red"
android:layout_width="match_parent"
android:layout_height="match_parent">
</TextView>
MainActivity:
protected void onCreate(Bundle savedInstanceState) {
private String[] data1;
private ArrayAdapter<String> adapter1 ;
private AutoCompleteTextView act_main_act1;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
act_main_act1=(AutoCompleteTextView)findViewById(R.id.act_main_cat1);//版本原因,有些需要强转有些不需要
//获取数据
data1 = new String[] { "愤怒的小鸟", "汤姆猫", "落汤鸡", "牛牛", "哈巴狗", "神龙", "烤鸭","小象", "美人鱼", "九尾狐" };
//创建适配器
adapter1 = new ArrayAdapter<String>( this,R.layout.act_main_item1,data1);
//绑定适配器
mtv_main_mtv1.setAdapter(adapter1);
}
}
结果为: