我使用listView
实现了使用autoCompleteTextView
搜索项目的代码。代码如下:
public class SearchActivity extends Activity {
ArrayAdapter<String> myAdapter;
ListView listView;
String[] dataArray = new String[] {"India","America", "Russia", "China", "Nepal", "Japan"};
private AutoCompleteTextView actv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search);
actv = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
listView = (ListView) findViewById(R.id.listview);
myAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, dataArray);
listView.setAdapter(myAdapter);
listView.setTextFilterEnabled(true);
actv.setAdapter(myAdapter);
actv.setThreshold(1);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
}
});
}
}