AutocompleteTextView in Android

/* main.xml */ <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <TextView android:id="@+id/select" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/app_name" /> <AutoCompleteTextView android:id="@+id/atv" android:layout_width="fill_parent" android:layout_height="wrap_content" android:completionThreshold="1"/> </LinearLayout> /* */ package com.icrg.test; import; import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; import android.widget.TextView; public class SampleAndroidNewProjectActivity extends Activity implements TextWatcher { private TextView selection; AutoCompleteTextView edit; static final String items[] = {"one","two","three","four", "five","six","seven","eight","nine","ten"}; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); selection = (TextView) findViewById(; edit = (AutoCompleteTextView) findViewById(; edit.addTextChangedListener(this); edit.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, items)); } public void afterTextChanged(Editable s) { } public void beforeTextChanged(CharSequence s, int start, int count,int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { selection.setText(edit.getText()); } }
AutoCompleteTextView is a sort of hybrid between the EditText & the Spinner. With autocompletion, as the user types, the text is treated as a prefix filter. Matches are shown in a selection list that drops down from the field (spinner).

AutoCompleteTextView is subclass of EditText, so you can configure all the standard look & feel aspects such as font face and color. In addition, this widget has a “android:completionThreshold ” property, to indicate the minimum number of characters a user must enter before the list filtering begins.

#android $autocomplete #textview


Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.