Autocomplete TextView and Multi Autocomplete TextView

0

 Autocomplete TextView and Multiple AutocompleteTextView:-

Autocomplete is used to provide autosuggestion text according to input char, if we want to get suggestions  for multiple word using comma or another separator that is called tokenizer then we can implement multi Autocomplete Textview for multiple searching of data.


AutoCompleteTextView Example:-

package com.example.customdrawer;

import androidx.appcompat.app.AppCompatActivity;

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

public class MainActivity3 extends AppCompatActivity {

AutoCompleteTextView act;
String course[] = {"JAVA",".NET","PHP","iOS","Android","Android Advance"," JAVA Advance", "J2SE","J2EE"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
act =(AutoCompleteTextView)findViewById(R.id.autocomplete2);
ArrayAdapter aa = new ArrayAdapter(this,android.R.layout.select_dialog_item,course);
act.setThreshold(1);
act.setAdapter(aa);
//
//act.setAdapter(aa);


}
}

Code of design file:-

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity3">

<AutoCompleteTextView
android:layout_width="200dp"
android:layout_height="80dp"
android:id="@+id/autocomplete2">

</AutoCompleteTextView>



</LinearLayout>

Example of MultiAutocompleteTextView:-
package com.example.customdrawer;

import androidx.appcompat.app.AppCompatActivity;

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

public class MainActivity4 extends AppCompatActivity {

MultiAutoCompleteTextView mac;
String course[] = {"JAVA",".NET","PHP","iOS","Android","Android Advance"," JAVA Advance", "J2SE","J2EE"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main4);
mac = findViewById(R.id.multiautocomplete);
ArrayAdapter aa = new ArrayAdapter(this,android.R.layout.select_dialog_item,course);
mac.setThreshold(1);
mac.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
mac.setAdapter(aa);
}
}

Code for Design File:-

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity4">

<MultiAutoCompleteTextView
android:layout_width="200dp"
android:layout_height="70dp"
android:id="@+id/multiautocomplete">

</MultiAutoCompleteTextView>

</LinearLayout>




Post a Comment

0Comments

POST Answer of Questions and ASK to Doubt

Post a Comment (0)