2016-05-22 5 views

Antwort

0

den Code unten verwenden:

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" 
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> 

    <AutoCompleteTextView 
     android:id="@+id/autoCompleteTextView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:ems="10" 
     android:layout_below="@+id/imageView" 
     android:layout_alignLeft="@+id/imageView" 
     android:layout_alignStart="@+id/imageView" 
     android:layout_marginTop="72dp" 
     android:hint="AutoComplete TextView"> 
     <requestFocus /> 
    </AutoCompleteTextView> 

</RelativeLayout> 

Java-Code:

AutoCompleteTextView text; 
String[] languages={"Android ","java","IOS","SQL","JDBC","Web services"}; 


@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     text=(AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1); 


     ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,languages); 

     text.setAdapter(adapter); 
     text.setThreshold(1); 


    } 

Verwenden Sie diesen Code, um die Ausgabe zu erhalten.

+0

Dies schlägt automatisch nur Strings vor. Wie kann ich Bilder automatisch vorschlagen? – mercury0114