AutoComplete自动填充控件

一、AutoCompleteTextView的应用

 

private static final String[] autoStr = new String[] { "abb", "abc",
			"abcd", "abcde" };

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		/* 载入main.xml Layout */
		setContentView(R.layout.complete);
		/* new ArrayAdapter对象并将autoStr字符串数组传入 */
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
				android.R.layout.simple_dropdown_item_1line, autoStr);
		/* 以findViewById()取得AutoCompleteTextView对象 */
		AutoCompleteTextView myAutoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
		/* 将ArrayAdapter加入AutoCompleteTextView对象中 */
		myAutoCompleteTextView.setAdapter(adapter);
	}


AutoComplete自动填充控件

 

二、MultiAutoCompleteTextView的应用

private static final String[] autoStr = new String[] { "abb", "abc",
			"abcd", "abcde" };
	
	private MultiAutoCompleteTextView mt;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		/* 载入main.xml Layout */
		setContentView(R.layout.multi_complete);
		/* new ArrayAdapter对象并将autoStr字符串数组传入 */
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
				android.R.layout.simple_dropdown_item_1line, autoStr);
		mt = (MultiAutoCompleteTextView) findViewById(R.id.multiAutoCompleteTextView1);
		mt.setAdapter(adapter);
		mt.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
	}
 


AutoComplete自动填充控件

你可能感兴趣的:(autocomplete)