Saving Records Into The Database From The Hashmap In Android
I just wanted to ask help for this one. I have a hashmap populate in the listview. the code below is my code for my hashmap: mylist = new ArrayList
Solution 1:
SQLiteDatabase db = mDbHelper.getDatabase();
db.beginTransaction();
for(HashMap<String, String> map : mylist){
ContentValues cv = new ContentValues();
cv.put(FILE_NAME, map.get(FILE_NAME));
cv.put(DESC, map.get(DESC));
cv.put(UPLOADED_BY, map.get(DATE_UPLOADED));
cv.put(ACTION, map.get(FILE_NAME));
cv.put(ID, map.get(ID));
cv.put(FILE_URI, map.get(FILE_URI));
db.insert("tablename", null, cv);
}
db.setTransactionSuccessful();
db.endTransaction();
db.close();
A database helper will need to be implemented by you, the string keys will need to match the column names. You can read more on database helpers here: http://developer.android.com/training/basics/data-storage/databases.html
Post a Comment for "Saving Records Into The Database From The Hashmap In Android"