
Untitled
By: a guest on
Aug 11th, 2012 | syntax:
None | size: 1.38 KB | hits: 8 | expires: Never
Dynamically changing SharedPreferences
public void setMonth(SharedPreferences sp) {
ContentValues cv = new ContentValues();
cv.clear();
int sel_month = Integer.valueOf(sp.getString("pActivityMonth", String.valueOf(this.month))); //listvew works with strings, convert to int
int stored_new = 0; //default value
int stored_ren = 0; //default value
Log.d(TAG, String.valueOf(sel_month));
String[] col = { Database.C_MONTH, Database.C_QNEW, Database.C_QRENEW };
String[] arg = { String.valueOf(sel_month) };
Cursor c = db.query(Database.RR_TABLE, col, Database.C_MONTH + "=?", arg, null, null, null);
if (c.getCount()<1) { //New month, insert row
cv.put(Database.C_MONTH, sel_month);
db.insertWithOnConflict(Database.RR_TABLE, null, cv, SQLiteDatabase.CONFLICT_IGNORE);
} else { //row exists, get stored values
Log.d(TAG, "cursor count: " + String.valueOf(c.getCount()));
c.moveToFirst();
stored_new = c.getInt(c.getColumnIndex(Database.C_QNEW));
stored_ren = c.getInt(c.getColumnIndex(Database.C_QRENEW));
Log.d(TAG, "stored_new: " + String.valueOf(stored_new));
}
//Change edittext preferences to stored values
editor.putString("pNewQuota", String.valueOf(stored_new));
editor.putString("pRenewQuota", String.valueOf(stored_ren));
editor.apply();
editor.commit();
}