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);
android arraylist autocompletetextview
chris
source share