Wednesday 14 November 2012

AutoCompleteTextViewDemo

Demo:

AutoCompleteTextView DemoActivity.java:

package com.venky.autocompletetextview;

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

public class AutoCompleteTextViewDemoActivity extends Activity {
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

            AutoCompleteTextView auto = (AutoCompleteTextView) 
                                                                findViewById(R.id.auto);

            String[] subjects = { "Android", "AndroidBooks", "AndroidGames",
                        "AndroidTheames", "AndroidMobiles", "AndroidTablets",
                        "AndroidDeveloper", "AndroidSoftware" };

            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                        android.R.layout.simple_list_item_1, subjects);

            auto.setAdapter(adapter);

      }

}

main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#5F04B4"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="30dp"
        android:text="AutoComplete TextView"
        android:textSize="15dp"
        android:textStyle="bold" />

    <AutoCompleteTextView
        android:id="@+id/auto"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:completionThreshold="2"
        android:popupBackground="#000000"
        android:textColor="#FF0000" />

</LinearLayout>


Download this Project Click Here

No comments:

Post a Comment