package com.example.autocompletetext;
import android.R.anim;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
public class MainActivity extends Activity {
private static final String[] array=new String[]{"asd","asc","asa","asf"};
//首先声明了一个数组,这里以后可以用数据库
@SuppressWarnings("rawtypes")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
@SuppressWarnings("unchecked")
// ArrayAdapter adapter=new ArrayAdapter(this,android.R.layout.simple_list_item_1,array);
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,array );
//一个适配器,用“R.layout.simple_dropdown_item_1line”的方式显示“array”
AutoCompleteTextView act=(AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);
act.setAdapter(adapter);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}