Monday, 28 October 2013

MultiAutoCompleteTextView Example

An editable text view, extending AutoCompleteTextView, that can show completion suggestions for the substring of the text where the user is typing instead of necessarily for the entire thing.You must provide a MultiAutoCompleteTextView.Tokenizer to distinguish the various substrings.

Example:

    



activity_main.xml


<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:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="20dp"
        android:gravity="center"
        android:text="MultiAutoCompleteTextView "
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textStyle="bold" />

    <MultiAutoCompleteTextView
        android:id="@+id/multiAutoCompleteTextView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="100dp"
        android:ems="10" >

        <requestFocus />
    </MultiAutoCompleteTextView>

</LinearLayout>


MainActivity.java


package in.androiddevelopmentanddiscussion.multiautocompletetextview;

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

public class MainActivity extends Activity {
MultiAutoCompleteTextView mtv;
String[] str={"Andoid","Jelly Bean","Froyo","Ginger Bread","Eclipse Indigo","Eclipse Juno"};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mtv = (MultiAutoCompleteTextView)findViewById(R.id.multiAutoCompleteTextView1);
mtv.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
ArrayAdapter<String> adp = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,str);
mtv.setThreshold(1);
mtv.setAdapter(adp);
}

}


Download full project from here




Check Android Apps on Google Play

https://play.google.com/store/apps/developer?id=Metro%20App%20Solution&hl=en