Use AutoCompleteTextView

Description

The AutoCompleteTextView control is a TextView with auto-complete functionality. As you types in the TextView, the control can display suggestions for selection.

Example

The following code shows how to use the AutoCompleteTextView control with XML and with the corresponding code.


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">
// w  w  w. j  a v a  2 s  . c  om
    <AutoCompleteTextView
        android:id="@+id/myID"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

The Java code.


    // ww  w . ja va  2 s.c  o m
package com.java2s.app;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;

public class MainActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        AutoCompleteTextView actv = (AutoCompleteTextView) this.findViewById(R.id.myID);

        ArrayAdapter<String> aa = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line,
                new String[]{"XML", "CSS", "HTML", "Java",
                        "SQL", "Code"}
        );

        actv.setAdapter(aa);
    }

}
    
Use AutoCompleteTextView




















Home »
  Android »
    Android UI »




UI Basics
Action Bar
Animation
Button
Canvas
CheckBox
Clock Date Picker
Dialog
EditText
Event
Fragment
Gesture
GridView
ImageView
Layout
ListView
Map
Menu
Model
OpenGL
ProgressBar
RadioButton
Spinner
Tab
TextView
Thread
Toast
Video
View
WebView