我是新手在android中实现sql我需要在将数据存储到我的localdb之后显示一个列表,下面是我的代码片段
private void getAllData() {
data.clear();
Cursor mCursr_all = SFMApp.localDBS.fetchMyPurchaseAllGroupBy(activity, SFMTableCreate.TABLE_SFM_STORE_MYPURCHASE, null);
Log.e("mCursor","::::::"+mCursr_all.getPosition()+":::::"+mCursr_all.getColumnNames());
data.addAll(new SFMCursorFactory().fetchMyPurchaseMaster(mCursr_all, SFMTableCreate.getColoumnArrayCallMYPURCHASE()));
if (mCursr_all == null) {
//Toast.makeText(activity,"Cursor value is null",Toast.LENGTH_SHORT).show();
} else {
for (int i = 0; i <data.size() ; i++) {
String data1 = data.get(i).getPurchaseNo();
Log.e("PURCHASE Key:::::","::::::::====="+data1);
}
purchaseAdapter = new SFMMyPurchaseAdapter(activity, data,SFMMyPurchase.this);
callloglist.setAdapter(purchaseAdapter);
}
dismissProgress();
}
这里的上面的代码数据是我的数据模型的arraylist fetchMyPurchaseAllGroupBy函数在下面
public Cursor fetchMyPurchaseAllGroupBy(Context context, String table, String[] columns) {
SQLiteDatabase db = context.openOrCreateDatabase(
SFMAppConfig.DB_NAME, SQLiteDatabase.OPEN_READWRITE, null);
String query;
query = "Select * from " + table + " GROUP BY "+SFMTableCreate.COLOUMNS_SFM_CALL_MYPURCHASE.PurchaseKey.name();
Log.e("Query", query);
Cursor mCursor = db.rawQuery(query, null);
/*Cursor mCursor = db.query(table, columns,
SFMTableCreate.COLOUMNS_SFM_ASSET_TAG_LOG_MASTER.vcCode.name(), null, null, null, SFMTableCreate.COLOUMNS_SFM_ASSET_TAG_LOG_MASTER.vcCode.name() + " DESC");*/
if (mCursor != null && mCursor.getCount() != 0 && mCursor.moveToFirst()) {
Log.e("fetchAll", "notNull");
Log.e("row count", "" + mCursor.getCount());
} else {
Log.e("fetchAll", "Null");
mCursor = null;
}
db.close();
return mCursor;
}
和fetchMyPurchaseMaster func位于
之下 public ArrayList<MyPurchaseData> fetchMyPurchaseMaster(Cursor mCursor, String[] columns) {
ArrayList<MyPurchaseData> aData = new ArrayList<MyPurchaseData>();
if (mCursor == null)
return aData;
int[] columnIndex = new int[columns.length];
for (int i = 0; i < columnIndex.length; i++)
columnIndex[i] = mCursor.getColumnIndex(columns[i]);
Log.e("ColumnIndex",":::::"+columnIndex);
do {
MyPurchaseData data = new MyPurchaseData();
int j = 0;
data.setPurchaseKey(mCursor.getInt(columnIndex[j++]));
data.setPurchaseDate(mCursor.getString(columnIndex[j++]));
data.setPurchaseNo(mCursor.getString(columnIndex[j++]));
data.setNetAmount(mCursor.getInt(columnIndex[j++]));
data.setVendorName(mCursor.getString(columnIndex[j++]));
data.setItemName(mCursor.getString(columnIndex[j++]));
data.setUnit(mCursor.getString(columnIndex[j++]));
data.setQTY(mCursor.getInt(columnIndex[j++]));
data.setRATE(mCursor.getInt(columnIndex[j++]));
j = 0;
aData.add(data);
} while (mCursor.moveToNext());
Log.e("cursor size", String.valueOf(aData.size()));
return aData;
}
我的json回复链接http://mobile.spectrafm.com/SPFMWEBAPI2/api/Stores/GetPurchaseList/03/2018/SPFM002
请在这里帮助我如何使用GROUPBY查询并使屏幕显示为上面给出的图像
注意目前正在