how to delete the particular selected item from the list of items in spinner

I followed this one to add the values in the spinner.In it while we select the "clear spinner items" the whole events are will be delete. But i need to the selected particular item only want to delete.Any one can help me.. The sample code will help to me lot.

-------------Problems Reply------------

To delete particular item from spinner you have to remove it from arrayadapter which is you using for filling it.

so first get the position of item you r wanting to delete.

than get the object frm arrayadapter from its position by mehod.

int pos = 0;object t=m_adapterForSpinner.getitem(pos);//whr m_arrayadapter is array adapter using for filling spinner

and than remove it from spinner by using following code:

m_adapterForSpinner.remove((CharSequence) t);

than fill ur spinner again with arrayadapter.

If you want to remove the selected item in the spinner:


where "adapter" is the adapter set to the spinner, it's as simple as that. :)

if adapter is out of scope you can get the adapter from the spinner, cast properly and remove the item:

((List<String>) spinner.getAdapter()).remove((String)spinner.getSelectedItem());
((List<String>) spinner.getAdapter()).notifyDataSetChanged();

Category:android Views:1 Time:2011-01-24

Related post

Copyright (C), All Rights Reserved.

processed in 0.195 (s). 11 q(s)