I'm using a spinner in my apps so i need a button reset .on click on clearButton button spinner should clear (no value should be displayed )
spinner= (Spinner) view.findViewById(R.id.mylistspinner);
list= new ArrayList<String>();
list.add("");
list.add("1");
list.add("2");
adapter= new ArrayAdapter<String>(getActivity(),R.layout.custom_spinner_text,list);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(urineGlucoseAdapter);
spinner.setOnItemSelectedListener(new OnUGItemSelected());
when you select one of your first spinner Items you can use code below in first spinner onItemSelected() method to clear your second spinner. Show activity on this post. You have called spinner2List. clear(); but haven't notified the adapter by using notifyDataSetChanged(); method.
two way u can do it on click of button use either
arr.clear();
spinner.setAdapter(null);
or
arr.clear();
spinner.setAdapter(new ArrayAdapter<String>(YourActivity.this,android.R.layout.simple_dropdown_item_1line,arr));
units = new String[0];
Arrays.fill(units, null);
Log.i("units array length", ""+units.length);
unit_adapter = new ArrayAdapter<String>(MyActivity.this, android.R.layout.simple_spinner_item, units);
spinner.setAdapter(unit_adapter);
// unit_adapter.notifyDataSetChanged();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With