Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ormlite, listViews and adapters?

I have OrmLite running in my app with database helpers and so forth. I have looked in the OrmLite's examples and some tutorials. This is my code for using listViews:

Database manager:

public List<Artist> getAllArtists() {
    List<Artist> artists = null;
    try {
        artists = getHelper().getArtistDao().queryForAll();
    } catch (SQLException e) {
            e.printStackTrace();
    }
    return artists;
}

Activity:

List<Artist> artists = dataBase.getAllArtists(); 

for (Artist artist : artists) {
     items.add(artist);
}

mAdapter = new ArtistsListCustomAdapter(getActivity(), items);
listView.setAdapter(mAdapter);

Is this an ok way or will there be trouble down the road using my method?

From other sources I have read that should use CursorAdapter for listViews and not the BaseAdapter (which I am now extending in ArtistsListCustomAdapter()). To me it seems awkward to iterate over the result a second time to create the array.

I have found some clues regarding using adapters this but since I am rather new to Android in general, I would really appreciate more clues to "connect the dots". In my case, should getAllArtists() return a Cursor? It seems complicated for such an easy task:

Android Cursor with ORMLite to use in CursorAdapter

like image 266
jannej Avatar asked Sep 19 '12 07:09

jannej


1 Answers

Take a look on this:

https://github.com/campnic/ormlite-android-extras

They have implementation of ormlite cursor adapter.

like image 88
Eugene Dudnyk Avatar answered Sep 19 '22 17:09

Eugene Dudnyk