开发者

Updating a spinner when SQLite is updated

I have an application where a user can enter in a EditText field an artist's name and it will be added to the sqlite table. That works great, but I also have a spinner on the same activity/layout that I want to update with these new changes. Here's how I have it setup:

I have a sqlite class that will insert the new name and method that will query the table and return an 'ArtistList' array.

In my activity, I'm able to get the ArtistList into the spinner using an Array Adapter when first created.

The user enters a new name in the EditText, updates the sqlite table, success...

I tried to reload the ArrayList and ArrayAdapter by running the sqlite method ArtistList but the spinner still doesn't update, it still has the same old list before the update. I know I can just doa artistList.add(), but that will make the list out of order. I would like to have this list in Alphabetical order which is why I'm retrieving the ArrayList from the sqlite class, the sqlite is organizing the data for me.

I tried using setNotifyOnChange, I tried a new (and clearing) arraylist and adapter...nothing is working.

This is ran onCreate:

sqlclass helper = new sqlclass(this);
        SQLiteDatabase db = helper.getWritableDatabase();
        artistList = helper.getArtistList(d开发者_JAVA技巧b, tableName);
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, artistList);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        adapter.setNotifyOnChange(true);

Thanks for your help!

Nevermind... I ended up making a new adapter...and added spinner.setAdapter(adapter). Not sure if that was supposed to be there because the spinner was displaying find until the update, but it's working now...


I apologize for this being vague but look into using a CursorAdapter ... I think it will allow you to re-query and update the data set.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜