Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to clear spinner value in android

i have two spinners when i select items(other then first item) in first spinner which is saved in array it populates data in spinner second which comes from web services. i want that when i again select first data which is title of spinner first it should clear all the value from spinner second. i did all tricks but helpless. suggest me.

my code is:

  if(spinner1== 0) {
        spinner2List.clear();
        ArrayAdapter<String> adapterEmpty = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, spinner2List);
        adapterEmpty.setDropDownViewResource(R.layout.spinner_layout);

        // Apply the adapter to the spinner
        spinner2.setAdapter(adapterEmpty);
    }

thanks.

like image 522
Avinash Kumar Pankaj Avatar asked Feb 05 '13 11:02

Avinash Kumar Pankaj


Video Answer


2 Answers

when you select one of your first spinner Items you can use code below in first spinner onItemSelected() method to clear your second spinner.

 Spinner2.setAdapter(null)
like image 56
Arash GM Avatar answered Oct 28 '22 17:10

Arash GM


You have called spinner2List.clear(); but haven't notified the adapter by using notifyDataSetChanged(); method.

like image 38
Paresh Mayani Avatar answered Oct 28 '22 19:10

Paresh Mayani