自动匹配输入控件AutoCompleteTextView和Multi AutoCompleteTextView
属性 android:completionThreshold="3"指输入到第几个字符开始匹配
下面给出实例:
<AutoCompleteTextView
android:id="@+id/AutoCompleteTextView_name"
android:completionThreshold="3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/content" />
<MultiAutoCompleteTextView
android:id="@+id/AutoCompleteTextView_name2"
android:completionThreshold="3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/content" />
然后是Java文件:
//1、首先初始化控件
//2、获取适配器
//3、控件与适配器结合
//4、MultiAutoCompleteTextView要设置分隔符
String[] res = {"xiaoming","xiaohong","xiaolan","xiaoln"};
acTV = (AutoCompleteTextView)findViewById(R.id.AutoCompleteTextView_name);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1, res);
acTV.setAdapter(adapter);
macTV = (MultiAutoCompleteTextView) findViewById(R.id.AutoCompleteTextView_name2);
macTV.setAdapter(adapter);
//设置分隔符
macTV.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
这里simple_list_item_1实现的效果还是白字白底的,看不清,求请教怎么改
网友评论