6

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

Community
  • 1
  • 1
jannej
  • 864
  • 14
  • 26

1 Answers1

1

Take a look on this:

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

They have implementation of ormlite cursor adapter.

Eugene Dudnyk
  • 5,553
  • 1
  • 23
  • 48