I have a ListView which I populate with data from a database.
ArrayList<HashMap<String, String>> userList = dBcode.getAllUsers();
ListAdapter adapter = new SimpleAdapter(
Main_Activity.this,userList, R.layout.list_view_search_item, new String[]
{ "name", "age", },
new int[] {R.id.name, R.id.Age});
It works perfectly well.
Now I want to create a new vResult for every row in the Listview with the values from the ListView, instead of typing it like the example below.
private Result[] resultArray = {
vResult("Thomas", "12"),
vResult("Mike", "15")};
This is the code to retrieve the data from the database.
public ArrayList<HashMap<String, String>> getAllUsers(){
ArrayList<HashMap<String, String>>userArrayList = new ArrayList<HashMap<String, String>>();
String selectQuery = "SELECT * FROM user ORDER BY name";
SQLiteDatabase database = this.getWritableDatabase();
Cursor cursor = database.rawQuery(selectQuery, null);
if(cursor.moveToFirst()){
do{
HashMap<String, String> contactMap = new HashMap<String, String>();
contactMap.put("name", cursor.getString(0));
contactMap.put("age", cursor.getString(1));
userArrayList.add(contactMap);
} while(cursor.moveToNext());
}
return userArrayList;
}
Thanks