Auto complete Text view
package app.test;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
public class Test extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setTitle("AutoCompleteTextViewActivity");
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, COUNTRIES);
AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.auto_complete);
textView.setAdapter(adapter);
}
static final String[] COUNTRIES = new String[] { "China", "Russia",
"Germany", "Ukraine", "Belarus", "USA", "China1", "China12",
"Germany", "Russia2", "Belarus", "USA" };
}
//main.xml
<?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/auto_complete"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
Related examples in the same category