views:

234

answers:

3

I've been trying to update my spinner in android dynamically but nothing I try has been working.

This is the following code I'm using to update the spinner.

typeList = dbAdapter.getList(); //array list with the values

adapter.notifyDataSetChanged();
groupSpinner.postInvalidate();
groupSpinner.setAdapter(adapter);

The values of typeList are correct but they're not being updated in the Spinner.

Thanks

A: 

Is there a typo or something? Which is the difference between dbAdapter and adapter. If the Spinner has already the adapter, you don't have to re-assign it. More over, the only think you have to do is update the adapter and call notifyDataSetChanged method.

typeList = adapter.getList(); //array list with the values
// change the values, and then
adapter.notifyDataSetChanged();
Cristian
dbAdapter is my link to the database adapter is a custom adapter i made that extends BaseAdapter and implements SpinnerAdapter. I tried what you suggested and that did not work.
2Real
A: 

You only need to call setAdapter() once and you call adapter.notifyDataSetChanged() to update the data.

BrennaSoft
do I need to create a whole new adapter because that isn't working? When I click the spinner, the values in the list are not updated.
2Real
A: 

Actually, you either have to call clear/add on the adapter, or create and set a new adapter. The adapter does not retain a reference to your list (it is only calling toArray on your list at construction), so there is no way for it to update itself.

AdamC