天天看點

AutoCompleteTextView DEMO

布局:

<?xml version="1.0" encoding="utf-8"?>
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:orientation="vertical"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content" >
   
         <AutoCompleteTextView 
            android:id="@+id/autocomplete"       
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
            android:completionThreshold="1"
            android:hint="@string/input_ip"  />
         
         <Button 
         android:id="@+id/auto_complete_enter"
         android:layout_width="wrap_content"
    android:layout_height="@dimen/login_btn_height"
    android:text="@string/ok"
         />
         
</LinearLayout>
           

邏輯代碼:

String[] names = ...;
AutoCompleteTextView autoTV =(AutoCompleteTextView)findViewById(R.id.autocomplete);
ArrayAdapter<String> contact=new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line,names);