I have OrmLite working in my application with database helpers and so on. I looked through OrmLite 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 a suitable way or will there be problems with the road using my method?
From other sources that I read, you should use the CursorAdapter for listViews, not the BaseAdapter (which I am now expanding in ArtistsListCustomAdapter() ). It seems inconvenient for me to repeat the result a second time to create an array.
I found some tips regarding the use of adapters, but since I'm fairly new to Android in general, I would really appreciate additional tips to “connect the dots”. In my case, if getAllArtists() returns a Cursor ? Seems tricky for such an easy task:
Android cursor with ORMLite for use in CursorAdapter
source share