Korektní varianta:
Cursor cursor = db.rawQuery(selectQuery, null); ArrayList<HashMap<String, String>> maplist = new ArrayList<HashMap<String, String>>(); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { HashMap<String, String> map = new HashMap<String, String>(); for(int i=0; i<cursor.getColumnCount();i++) { map.put(cursor.getColumnName(i), cursor.getString(i)); } maplist.add(map); } while (cursor.moveToNext()); } db.close(); // return contact list return maplist; Naplnění ListView pomocí HashMap
//listplaceholder is your layout //"StoreName" is your column name for DB //"item_title" is your elements from XML ListAdapter adapter = new SimpleAdapter(this, mylist, R.layout.listplaceholder, new String[] { "StoreName", "City" }, new int[] { R.id.item_title, R.id.item_subtitle });Kurzor po dokončení nezapomeňte uzavřít i v případě výjimky — ideálně v bloku finally.