Just started learning how to program for Android and now I am stuck at some doubts.
I have one SQLite db with more than one table and each table with some fields.
I’ve created a class to manage my database and imagine that one of the functions is something like this:
public Cursor getGroupData() {
String[] values = new String[] {_ROWID, _NAME, _AGE, _PHONE};
Cursor c = db.query(BD_TABLE, values, null, null, null, null, null);
return c;
}
Now I have one of two situations.
FIRST SITUATION
Want to show, for example, all the names returned on my query in a ListView. With that, the user can click on a name and a new activity will show (imagine a layout with all the user information)
SECOND SITUATION
Want to show, for example, all the names returned on my query in a ListView. With that, the user can click on a name and a new query will be performed (Imagine get other data from that user). The query will result in returning various data and I, again, want to show some field in a ListView (for example the address). Now, if the user clicks on on of the address, a new activity will show up (for example a layout with some information about the address).
In both situation, although I’m just picking a name or an address, all the data returned by the SQLite must be available, for example, on the first situation, I pick a name, it will show on a layout, something like a contact information, but the results from the query, age and phone, must also be available.
For now I’m doing something like:
Cursor values = db.getGroupData();
// Now I'm thinking in putting some code to iterate over the cursor and put what I want to display on my listview on a string array
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, values_I_what_to_show);
setListAdapter(adapter);
The problem with this is that I’m putting the data on a string array but will need all the data returned by the query.
Can you point me In some direction?
Regards,
Try this :
Declare MyData class :
MyAdapter class :