Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make clear(empty/without values) spinner on clearbutton

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());
like image 379
H.S Avatar asked Jun 15 '12 05:06

H.S


People also ask

How to empty spinner in android?

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.


2 Answers

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)); 
like image 81
Khan Avatar answered Sep 28 '22 01:09

Khan


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();
like image 38
Maddy Avatar answered Sep 28 '22 03:09

Maddy