Activity_main.xml:
<AutoCompleteTextView android:id="@+id/autocomplete" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="5dp"/> list_item.xml: <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="10dp" android:textSize="16sp" android:textColor="#000"/>
MainActivity.java
package leihu.autocompletetextview; import java.util.ArrayList; import java.util.List; 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 AutoCompleteTextView autoCompleteTextView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); autoCompleteTextView = (AutoCompleteTextView)findViewById(R.id.autocomplete); List<String>list = new ArrayList<String>(); list.add("艳阳高照"); list.add("艳阳满天"); ArrayAdapter<String>arrayAdapter=new ArrayAdapter<String>(this,R.layout.list_item,list); autoCompleteTextView.setAdapter(arrayAdapter); } }