How to update an Spinner dynamically correctly?

前端 未结 3 859
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-18 09:09

I have a spinner with a custom adapter displaying objects from a database. When the object list changed I create a new adapter with the List and apply it on the spinner. Aft

3条回答
  •  青春惊慌失措
    2020-12-18 09:36

    Solved: I guess the main problem was the custom spinner adapter. This works fine now

    if (spinner.getCount() > 0) {
        pos = spinner.getSelectedItemPosition();
    }
    MySpinnerAdapter adapter = new MySpinnerAdapter(context, myNewObjects);
    spinner.setAdapter(adapter);
    spinner.setSelection(pos); // needed
    adapter.notifyDataSetChanged();
    

提交回复
热议问题