Saturday, September 8, 2012

Autocomplete Text in TextView In Android

This example shows how to crating rating bar in android.
1.) Create a new project by File-> New -> Android Project name it AutocompleteText.
2.) Write following code into your main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
        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="Items" />
        <AutoCompleteTextView android:id="@+id/autocomplete_country"
                android:layout_marginLeft="5dp" />
3.) Create and write following code into your res/layout/list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android=""
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:padding="10dp" android:textSize="16sp"android:textColor="#000"></TextView>
4.) Build and run your code and check the output given below in the doc.
1.) Create a project named AutocompleteText and set the information as stated in the image.
Build Target: Android 3.0
Application Name: AutocompleteText
Package Name: AutocompleteText
Activity Name: AutocompleteText
Min SDK Version: 11
2.) Open file and write following code there:
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
public class AutocompleteTextActivity extends Activity {
    /** Called when the activity is first created. */
        static final String[] ITEMS = new String[] { "Tea",
                "Coffee""Milk""Expresso""Lemon Tea""Cappuciano",
                "Hot Water""Tomato Soup""Ginger Tea""ColdDrink"};
    protected void onCreate(Bundle savedInstanceState)
        AutoCompleteTextView textView = (AutoCompleteTextView)findViewById(;  
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_item, ITEMS);  
3.) Compile and build the project.
4.) Run on simulator and start typing some letters. It will show a list as soon as you start entering some letters.

No comments:

Post a Comment