AutoComplete Text View Tutorial For Android

This tutorial is about how to show Auto Complete text in Android.

Here its source code.

HelloAutoComplete.java

public class HelloAutoComplete extends Activity {
static final String[] COUNTRIES = new String[] {
“Afghanistan”, “Albania”, “Algeria”,”Zimbabwe”
};

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
AutoCompleteTextViewtextView=(AutoCompleteTextView)findViewById(R.id.autocomplete_country);
ArrayAdapter<String>adapter=newArrayAdapter<String>(this,R.layout.list_item,COUNTRIES);
textView.setAdapter(adapter);
}

}
Main.xml

<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
android:orientation=”horizontal”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:padding=”5dp”>
<TextView
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”Country” />
<AutoCompleteTextView android:id=”@+id/autocomplete_country”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:layout_marginLeft=”5dp”/>
</LinearLayout>
list_item.xml
<?xml version=”1.0″ encoding=”utf-8″?>
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:padding=”10dp”
android:textSize=”16sp”
android:textColor=”#000″>
</TextView>

you can download complete source code from here

Other Important Links.

http://developer.android.com/resources/tutorials/views/hello-autocomplete.html

Advertisements
This entry was posted in Android and tagged , , . Bookmark the permalink.

2 Responses to AutoComplete Text View Tutorial For Android

  1. Harsha M V says:

    how make an array from the database. for example i wanna do a autocomplete for the usernames. and i want to do it from the database locally.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s