How to force the user to enter only the proposed item in the autocomplete list?

I am using Autocompltetextview, and I want the user to only accept the value of the proposed list. The user should not enter another value and send it. if the user did not select autocomplettextview, then I want to show a toast. can anyone help me solve this. check my fragment code and help me?

the code

actv = (AutoCompleteTextView)rootView.findViewById(R.id.search_donor_area); actv.setThreshold(1);//will start working from first character materialDesignSpinner.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { sel_blood_group=materialDesignSpinner.getText().toString(); Log.d("sel_blood_group",sel_blood_group); } }); citymaterialDesignSpinner = (MaterialBetterSpinner) rootView.findViewById(R.id.search_donor_city); citymaterialDesignSpinner.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // Log.d("POSITION", CITY_SPINNERLIST[position]); sel_city=citymaterialDesignSpinner.getText().toString(); Log.d("search_sel_city",sel_city); if (position == 0) { //Creating the instance of ArrayAdapter containing list of fruit names ArrayAdapter<String> areasadapter = new ArrayAdapter<String> (getActivity(), android.R.layout.select_dialog_item, AREA_DONOR); actv.setAdapter(areasadapter);//setting the adapter data into the AutoCompleteTextView } else if (position == 1) { //Creating the instance of ArrayAdapter containing list of fruit names ArrayAdapter<String> areasadapter = new ArrayAdapter<String> (getActivity(), android.R.layout.select_dialog_item, AREA_DONOR_RAJKOT); actv.setAdapter(areasadapter);//setting the adapter data into the AutoCompleteTextView } else if (position == 2) { //Creating the instance of ArrayAdapter containing list of fruit names ArrayAdapter<String> areasadapter = new ArrayAdapter<String> (getActivity(), android.R.layout.select_dialog_item, AREA_DONOR_SURAT); actv.setAdapter(areasadapter);//setting the adapter data into the AutoCompleteTextView } else if (position == 3) { //Creating the instance of ArrayAdapter containing list of fruit names ArrayAdapter<String> areasadapter = new ArrayAdapter<String> (getActivity(), android.R.layout.select_dialog_item, AREA_DONOR_BARODA); actv.setAdapter(areasadapter);//setting the adapter data into the AutoCompleteTextView } } }); ArrayAdapter<String> cityarrayAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_dropdown_item_1line, CITY_SPINNERLIST); citymaterialDesignSpinner.setAdapter(cityarrayAdapter); actv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Log.e("========>>", actv.getText().toString()); sel_area=actv.getText().toString(); } }); search_button = (Button)rootView.findViewById(R.id.search_button); 
+1
android arraylist autocompletetextview
source share

No one has answered this question yet.

See similar questions:

77
How to use the TextWatcher class in Android?
7
AutoCompleteTextView allows only suggested options

or similar:

286
Update ViewPager dynamically?
4
getFragmentManager returns an exception from a null pointer
3
View filter list from edit text
2
setText on a button from another type of Android activity
2
AutoCompleteTextView forcibly displays all elements or disables filtering
0
Associating an ID with Android List Presentation Strings
0
Remove leading zero in a text editor from a custom zero button in Android
0
AutoCompleteTextView - how to determine which item in the source list is selected?
0
Search in ListView when class extends ListActivity
0
I want to display an image from the Internet from the main lesson to another lesson?

All Articles