WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

MultiAutoCompleteTextView Android


MultiAutoCompleteTextView is an editable TextView extends AutoCompleteTextView that it is work for sub-string of a text allowing user to quickly select instead of typing whole.


Demo code of xml MultiAutoCompleteTextView
<MultiAutoCompleteTextView
android:id="@+id/simpleMultiAutoCompleteTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="This Is A MultiAutoCompleteTextView" />

MultiAutoCompleteTextView Methods Android

setTokenizer(MultiAutoCompleteTextView.Tokenizer t)This Tokenizer determine the relevant range of the text where user are typing.
// initiate a MultiAutoCompleteTextView
MultiAutoCompleteTextView simpleMultiAutoCompleteTextView = (MultiAutoCompleteTextView) findViewById(R.id.demoMultiAutoCompleteTextView);
// set tokenizer that distinguish the various substrings by comma
simpleMultiAutoCompleteTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());

setThreshold(int threshold) This method is used to set threshold value that help what we are searching from a specific character.

// initiate a MultiAutoCompleteTextView
MultiAutoCompleteTextView simpleMultiAutoCompleteTextView = (MultiAutoCompleteTextView) findViewById(R.id.demoMultiAutoCompleteTextView);
// set threshold value 2 that help us to start the searching from second character
demoMultiAutoCompleteTextView.setThreshold(2);

Attributes MultiAutoCompleteTextView

id This attribute is used to unique identify a MultiAutoCompleteTextView.
<MultiAutoCompleteTextView
android:id="@+id/demoMultiAutoCompleteTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="This Is A MultiAutoCompleteTextView" /> 
textThis attribute is used to set the text in a MultiAutoCompleteTextView
 
MultiAutoCompleteTextView simpleMultiAutoCompleteTextView = (MultiAutoCompleteTextView) findViewById(R.id.demoMultiAutoCompleteTextView);
simpleMultiAutoCompleteTextView.setText("Welookups"); // set text in a MultiAutoCompleteTextView

hint This attribute is used to set the hint that what should you enter in this MultiAutoCompleteTextView

<MultiAutoCompleteTextView
android:id="@+id/demoMultiAutoCompleteTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Enter Your Text Here" /> 
set up data MultiAutoCompleteTextView Java class:
MultiAutoCompleteTextView demoMultiAutoCompleteTextView = (MultiAutoCompleteTextView) findViewById(R.id.demoMultiAutoCompleteTextView);
demoMultiAutoCompleteTextView.setHint("Enter Your Text Here"); // set hint in a MultiAutoCompleteTextView
textColorThis attribute is used to set the text color of a MultiAutoCompleteTextView
<MultiAutoCompleteTextView
android:id="@+id/simpleMultiAutoCompleteTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="welookups.com"
android:textColor="#00f"/>
 

setup java class
MultiAutoCompleteTextView simpleMultiAutoCompleteTextView = (MultiAutoCompleteTextView) findViewById(R.id.demoMultiAutoCompleteTextView);
demoMultiAutoCompleteTextView.setTextColor(Color.Blue); // Blue color for the displayed text of a MultiAutoCompleteTextView

backgroundThis attribute is used to set the background of a MultiAutoCompleteTextView



setup java class
MultiAutoCompleteTextView simpleMultiAutoCompleteTextView = (MultiAutoCompleteTextView) findViewById(R.id.demoMultiAutoCompleteTextView);
simpleMultiAutoCompleteTextView.setBackgroundColor(Color.BROWN); // green color for the background of a MultiAutoCompleteTextView
padding This attribute is used to set the padding from left, right, top or bottom side of a MultiAutoCompleteTextView.
<MultiAutoCompleteTextView
android:id="@+id/simpleMultiAutoCompleteTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="welookups.Com"
android:textColor="#f00"
android:textSize="25sp"
android:textStyle="bold"
android:background="#A52A2A"
android:paddingLeft="40dp"/>


textSize This attribute is used to set the size of text of a MultiAutoCompleteTextView.
<MultiAutoCompleteTextView
android:id="@+id/simpleMultiAutoCompleteTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="welookups.Com"
android:textColor="#ff0"
android:textSize="25sp"/>

MultiAutoCompleteTextView android create new project and name it MultiAutoCompleteTextView res -> layout ->activity_main.xml (or) main.xml
<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=".MainActivity">



<MultiAutoCompleteTextView
android:id="@+id/simpleMultiAutoCompleteTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#0ff"
android:gravity="center"
android:hint="Enter Your Text Here"
android:padding="10dp"
android:textColor="#000"
android:textSize="30sp"
android:textStyle="bold" />




src -> package -> MainActivity.java

package example.welookups.multiautocompletetextviewexample;



import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ArrayAdapter;
import android.widget.MultiAutoCompleteTextView;

public class MainActivity extends AppCompatActivity {

String[] androidVersionNames = {"Nougat","Oreo","Android P","Android Q" };

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// initiate a MultiAutoCompleteTextView
MultiAutoCompleteTextView simpleMultiAutoCompleteTextView = (MultiAutoCompleteTextView) findViewById(R.id.simpleMultiAutoCompleteTextView);
// set adapter to fill the data in suggestion list
ArrayAdapter versionNames = new ArrayAdapter(this, android.R.layout.simple_list_item_1, androidVersionNames);
simpleMultiAutoCompleteTextView.setAdapter(versionNames);

// set threshold value 1 that help us to start the searching from first character
simpleMultiAutoCompleteTextView.setThreshold(1);
// set tokenizer that distinguish the various substrings by comma
simpleMultiAutoCompleteTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
}
}