Android MultiAutoCompleteTextView Tutorial Example

MultiAutoCompleteTextView is same as autocompletetextview but there is a major difference between both of them that autocompletetextview can hold or select only single value at single time but MultiAutoCompleteTextView can hold multiple string words value at single time. These all values are separated by comma(,). So here is the complete tutorial for Android MultiAutoCompleteTextView Tutorial Example.

android-project-download-code-button

Android MultiAutoCompleteTextView Tutorial Example.

Code for MainActivity.java programming file.

 package com.android_examples.com.multiautocompletetextview;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.MultiAutoCompleteTextView;

public class MainActivity extends Activity {

 MultiAutoCompleteTextView MultipleValuesholdt;
 String[] MultipleTextStringValue = { "Android","Android-MultiAutoCompleteTextView","Android Top Tutorials" };
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 MultipleValuesholdt = (MultiAutoCompleteTextView)findViewById(R.id.MultiAutoCompleteTextView1);
 ArrayAdapter<String> TopicName = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, MultipleTextStringValue);
 MultipleValuesholdt.setAdapter(TopicName);
 MultipleValuesholdt.setThreshold(3);
 MultipleValuesholdt.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
 }

}

Code for activity_main.xml layout file.

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.android_examples.com.multiautocompletetextview.MainActivity" >

 <MultiAutoCompleteTextView
 android:id="@+id/MultiAutoCompleteTextView1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignParentTop="true"
 android:layout_centerHorizontal="true"
 android:layout_marginTop="108dp"
 android:ems="10"
 >

 <requestFocus />
 </MultiAutoCompleteTextView>

</RelativeLayout>

Screenshot:

Android MultiAutoCompleteTextView Tutorial Example

Click Here To Download Android MultiAutoCompleteTextView Tutorial Example Project.

Leave a Reply

Your email address will not be published. Required fields are marked *