首先在layout布局文件中 写出 AutoCompleteTextView控件
<AutoCompleteTextView
android:completionThreshold="2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/actv"
android:hint="请输入想要查询的关键词" //编辑框里面出现的提示文字
/>
在MainActivity类中.
private String[] res={"aaaa","aaaa","yy love xx","xx is god"};
actv=(AutoCompleteTextView)findViewById(R.id.actv);
ArrayAdapter<String> a = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, res);
actv.setAdapter(a);