I am using Autocompltetextview and I want user to allow only to accept the value of suggested list. User should not enter other value and submit. if user did not select the value of autocomplettextview then i want to show toast. can any one help me to solve this . check my snippet code and help me?
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);