Wednesday, July 11, 2012

AutoCompleteTextView in Android


Package Name  :  selva.auto

Project Name    :  AutoComplete

Version             :  1.5 ( Supports 1.5 and above versions)

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:orientation="vertical" >

   <TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Name of Fruits" />
  
   <AutoCompleteTextView android:id="@+id/txt"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />

</LinearLayout>


 AutoCompleteActivity.java

package selva.auto;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
public class AutoCompleteActivity extends Activity {
String[] Fruits = {
            "Apple",
            "Banana",
            "Orange",
            "Mango",
            "Grapes",
            "Jack Fruit",
            "Strawberry",
            "cucumber",
            "pumpkin"
    };
/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_dropdown_item_1line, Fruits);
        AutoCompleteTextView textView = (AutoCompleteTextView)findViewById(R.id.txt);
        textView.setThreshold(3);
        textView.setAdapter(adapter);
}
}


OUTPUT:
























Enter text "app" in textfield. It shows apple.






























Enter text "str" in textfield. It shows strawberry.

































Click Here to download source code

http://www.androidprogramz.in/

No comments:

Post a Comment