ITEEDU

AutoCompleteTextView自动完成文本

类似搜索引擎中键入开头几个字或字母,就出现一个下拉列表的功能。
 

package com.iteedu.autocompletetextview;

import android.app.Activity;
import android.os.Bundle;
import android.widget.*;

public class MainActivity extends Activity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		ArrayAdapter adapter = 
			new ArrayAdapter(this,
				android.R.layout.simple_dropdown_item_1line, COUNTRIES);
		AutoCompleteTextView textView = 
			(AutoCompleteTextView) findViewById(R.id.auto);
		textView.setAdapter(adapter);
	}

	static final String[] COUNTRIES = new String[] { "China", "Russia",
			"Germany", "Ukraine", "Belarus", "USA", "China1", "China12",
			"Germany", "Russia2", "Belarus", "USA" };
}