开发者

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

开发者 https://www.devze.com 2023-02-06 21:18 出处:网络
I followed http://www.designerandroid.com/?p=8开发者_开发问答 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 nee

I followed http://www.designerandroid.com/?p=8开发者_开发问答 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.


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

adapter.remove((String)spinner.getSelectedItem());
adapter.notifyDataSetChanged();

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();


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

So first get the position of item you are wanting to delete.

Then get the object from arrayadapter from its position by method.

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

And then remove it from spinner by using following code:

m_adapterForSpinner.remove((CharSequence) t);

Then fill your spinner again with arrayadapter.

0

精彩评论

暂无评论...
验证码 换一张
取 消