Android中AutoCompleteTextView完整示例(一)

MainActivity如下:

package cc.testautocompletetextview;

import cc.testautocompletetextview1.R;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.app.Activity;
/**
 * Demo描述
 * AutoCompleteTextView基本使用完整示例
 * 
 * 注意参数:
 * android:completionThreshold="2"
 * 
 * 参考资料:
 * 《疯狂Android讲义》 作者李刚
 *  Thank you very much
 */
public class MainActivity extends Activity {
	private AutoCompleteTextView mAutoCompleteTextView;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		init();
	}
   
	private void init(){
		mAutoCompleteTextView=(AutoCompleteTextView) findViewById(R.id.autoCompleteTextView);
		String [] emails=new String []{"[email protected]","[email protected]","[email protected]","[email protected]"};
		ArrayAdapter arrayAdapter
		=new ArrayAdapter(this, android.R.layout.simple_dropdown_item_1line, emails);
		mAutoCompleteTextView.setAdapter(arrayAdapter);
	}
	

}


main.xml如下:



    
    
    



你可能感兴趣的:(Android核心)