packagecom.example.autocompletetext;

importandroid.R.anim;
importandroid.os.Bundle;
importandroid.app.Activity;
importandroid.view.Menu;
importandroid.widget.ArrayAdapter;
importandroid.widget.AutoCompleteTextView;

publicclassMainActivityextendsActivity{
privatestaticfinalString[]array=newString[]{"asd","asc","asa","asf"};

//首先声明了一个数组,这里以后可以用数据库
@SuppressWarnings("rawtypes")
@Override
protectedvoidonCreate(BundlesavedInstanceState){

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
@SuppressWarnings("unchecked")
//ArrayAdapteradapter=newArrayAdapter(this,android.R.layout.simple_list_item_1,array);
ArrayAdapter<String>adapter=newArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,array);

//一个适配器,用“R.layout.simple_dropdown_item_1line”的方式显示“array”

AutoCompleteTextViewact=(AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);
act.setAdapter(adapter);


}

@Override
publicbooleanonCreateOptionsMenu(Menumenu){
//Inflatethemenu;thisaddsitemstotheactionbarifitispresent.
getMenuInflater().inflate(R.menu.activity_main,menu);
returntrue;
}

}