Why can't one add/remove items from an ArrayAdapter?

前端 未结 7 1180
一整个雨季
一整个雨季 2020-11-29 07:26

I am using an ArrayAdapter to populate the items to list in a android.widget.Spinner. That works all fine.

But now I wa

相关标签:
7条回答
  • 2020-11-29 07:48

    Here's the source code of ArrayAdapter#remove:

    public void remove(T object) {
        if (mOriginalValues != null) {
            synchronized (mLock) {
                mOriginalValues.remove(object);
            }
        } else {
            mObjects.remove(object);
        }
        if (mNotifyOnChange) notifyDataSetChanged();
    }
    

    The only thing that can throw an UnsupportedOperationException there is the line in the else-block. So the problem is that the list you're using doesn't support removing items. My guess is you're using an array. Try an ArrayList, for instance.

    edit: So yeah, what Mark said...

    0 讨论(0)
提交回复
热议问题