布局:
<AutoCompleteTextView android:id="@+id/auto" android:layout_width="match_parent" android:layout_height="wrap_content" android:completionThreshold="1" />
代码:
private AutoCompleteTextView auto; private ArrayAdapter<String> adapter; private List<String> list; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); list = new ArrayList<String>(); list.add("ab"); list.add("apple"); adapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, list); auto = (AutoCompleteTextView) findViewById(R.id.auto); auto.setAdapter(adapter); }