Ormlite, listViews and adapters?
Asked Answered
W

1

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

Weightlessness answered 19/9, 2012 at 7:20 Comment(0)
O
1

Take a look on this:

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

They have implementation of ormlite cursor adapter.

Oran answered 1/10, 2014 at 9:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.