Search code examples
androidspinner

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


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.


Solution

  • 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.