import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.MultiAutoCompleteTextView;
public class mainActivity extends Activity {
// 只输入一个字母不会有提示,至少要两个字母或一个中文
// 被搜索的关键字
String[] autoString = { "a", "aa", "aab", "be", "awg", "sefr", "wead",
"aehr", "aewrh", "abgna" };
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// 创建适配器
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, autoString);
// 对单个的自动提示设置适配器
AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.atone);
autoCompleteTextView.setAdapter(adapter);
// 对多个个的自动提示设置适配器
MultiAutoCompleteTextView multiAutoCompleteTextView = (MultiAutoCompleteTextView) findViewById(R.id.mcone);
multiAutoCompleteTextView.setAdapter(adapter);
// 设置分隔符(逗号)
multiAutoCompleteTextView
.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
}
}
[控件]自动提示 AutoCompleteTextView MultiAutoCompleteTextView
最新推荐文章于 2013-03-13 16:04:20 发布