1 package com.example.autocompletetextvewtest;
2
3 import java.util.List;
4
5 import android.app.Activity;
6 import android.os.Bundle;
7 import android.view.Menu;
8 import android.widget.ArrayAdapter;
9 import android.widget.AutoCompleteTextView;
10
11 public class MainActivity1 extends Activity {
12 private AutoCompleteTextView actv;
13
14 @Override
15 protected void onCreate(Bundle savedInstanceState) {
16 super.onCreate(savedInstanceState);
17 setContentView(R.layout.activity_main);
18 String[] strings = new String[] { "北京", "北京西站", "北京南站", "上海", "上海浦东机场" };
19 actv = (AutoCompleteTextView) findViewById(R.id.actv);
20 // 第二个参数是样式的Layout布局id,第三个参数是:显示具体样式的TextView的id
21 ArrayAdapter adapter = new ArrayAdapter(this,
22 R.layout.down, R.id.contentTextView, strings);
23 actv.setThreshold(1);
24 actv.setAdapter(adapter);
25 }
26
27 @Override
28 public boolean onCreateOptionsMenu(Menu menu) {
29 getMenuInflater().inflate(R.menu.activity_main, menu);
30 return true;
31 }
32
33 }