嗨,有人可以指出我如何将 arraylist 值插入数据库的正确方向。我有两个数组列表如下:
ArrayList<HashMap<String, String>> achieve_val = new ArrayList<HashMap<String, String>>();
ArrayList<HashMap<String, String>> achieve_vol = new ArrayList<HashMap<String, String>>();
HashMap<String, String> Achiev_Vol_map = new HashMap<String, String>();
Achiev_Vol_map.put(PRODUCT_CAKE, Achieve_Vcake);
Achiev_Vol_map.put(PRODUCT_YEASTEXTRACT, Achieve_Vyeastextract);
.
.
.
achieve_vol.add(Achiev_Vol_map);
我为此值创建了一个 POJO 类,如下所示:
public class ProductCategory {
ArrayList<HashMap<String, String>> achieve_val,achieve_vol ;
public ArrayList<HashMap<String, String>> getAchieve_val() {
return achieve_val;}
public void setAchieve_val(ArrayList<HashMap<String, String>> achieve_val) {
this.achieve_val = achieve_val;}
public ArrayList<HashMap<String, String>> getAchieve_vol() {
return achieve_vol;}
public void setAchieve_vol(ArrayList<HashMap<String, String>> achieve_vol) {
this.achieve_vol = achieve_vol;}
/**my constructor**/
public ProductCategory(ArrayList<HashMap<String, String>> achieve_val,
ArrayList<HashMap<String, String>> achieve_vol) {
super();
this.achieve_val = achieve_val;
this.achieve_vol = achieve_vol;}}
我将这些值传递给我的数据库适配器,如下所示
dbHelper.open();
dbHelper.topinchartsRecord(new ProductCategory(achieve_val,achieve_vol));
现在在我的数据库适配器中,我不确定如何访问这些 vlaues 并插入数据库,如下所示:
public void topinchartsRecord(ProductCategory productCategory) {
for(ArrayList<HashMap<String, String>> map : achieve_val){
ContentValues cv = new ContentValues();
cv.put(FILE_NAME, map.get(FILE_NAME));
db.insert("tablename", null, cv);
}
}