I have a database table with eight columns, with the following fields:
|_id|flag|HVID|Vname|Vdate|Vtime|Vcost|Vmedicine|
I am querying on this database to extract all records which belong to a certain 'HVID':
public Cursor fetchAllVac(String ID) {
String Key = ID;
Cursor mCursor = mDb.query(DATABASE_TABLE1, new String[] { IDx, FLAG,
HVID1, Vname1, VDate1, Vtime1, Vcost1, Vmedicine1 }, "HVID=?",
new String[] { Key }, null, null, null, null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
And in the Activity, I fetch values from the cursor and store them in an Array list:
public void Vacforshare() {
String B = null;
ArrayList<String> mArrayList = new ArrayList<String>();
mCursor = DBHelper.fetchAllVac(IDB);
if (mCursor.moveToFirst()) {
do {
try {
mArrayList.add(mCursor.getString(mCursor
.getColumnIndex("_id")));
mArrayList.add(mCursor.getString(mCursor
.getColumnIndex("flag")));
mArrayList.add(mCursor.getString(mCursor
.getColumnIndex("HVID")));
mArrayList.add(mCursor.getString(mCursor
.getColumnIndex("Vname")));
mArrayList.add(mCursor.getString(mCursor
.getColumnIndex("Vdate")));
mArrayList.add(mCursor.getString(mCursor
.getColumnIndex("Vtime")));
mArrayList.add(mCursor.getString(mCursor
.getColumnIndex("Vcost")));
mArrayList.add(mCursor.getString(mCursor
.getColumnIndex("Vmedicine")));
} catch (Exception h) {
}
} while (mCursor.moveToNext());
}
for (int i = 0; i < mArrayList.size(); i++) {
String G = (mArrayList.get(i));
B = B + G;
}
System.out.println("" + B);
}
What I am getting in B is a redundant(all rows) string of values (My records can be of multiple rows) I want to separate these values into Name-Value pairs, I am confused as how to achieve that.