What is auto complete text view android
Spoke Right
/ 20 Nov, 2023
what is auto complete text veiw android
To complete the words based on the reserved words, the Android AutoCompleteTextView is used in Android. Thus it is not required to write all the characters of the word. It is an editable text field. A list of suggestions is thus displayed in a drop-down menu. At a time only one suggestion or value can be selected by the user from the drop-down menu. The EditText class has a subclass named AutoCompleteTextView and the AutoCompleteTextView class has a subclass named MultiAutoCompleteTextView.
Android AutoCompleteTextView Example:
We are here demonstrating an example to display the Gender options in the AutoCompleteTextView in Android. A string array is used to store all the Gender options. And to display the array content, the ArrayAdapter class is used.
activity_main.xml:
In the activity_main.xml file, drag the AutoCompleteTextView and TextView from the pallet.
Activity class:(File: MainActivity.java) The code of AutoCompleteTextView is written in the MainActivity.java file. package com.example.radioapp;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
public class MainActivity extends AppCompatActivity {
String[] fruits ={"Apple","Banana","Papaya","Grapes","Orange","Pineapple","Guava"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Creating the instance of ArrayAdapter containing list of fruits names
ArrayAdapter adapter = new ArrayAdapter
(this,android.R.layout.select_dialog_item,fruits);
//Getting the instance of AutoCompleteTextView
AutoCompleteTextView actv = (AutoCompleteTextView)findViewById(R.id.autoCompleteTextView);
actv.setThreshold(1);//will start working from first character
actv.setAdapter(adapter);//setting the adapter data into the AutoCompleteTextView
actv.setTextColor(Color.RED);
}
} |
|
0 comments