我有一个包含八列的数据库表,其中包含以下字段:
|_id|flag|HVID|Vname|Vdate|Vtime|Vcost|Vmedicine|
我正在查询该数据库以提取属于某个“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;
}
在 Activity 中,我从光标中获取值并将它们存储在一个数组列表中:
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);
}
我在 B 中得到的是一个冗余(所有行)值字符串(我的记录可以是多行)我想将这些值分成名称-值对,我对如何实现这一点感到困惑。