Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 11th, 2012  |  syntax: None  |  size: 1.38 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Dynamically changing SharedPreferences
  2. public void setMonth(SharedPreferences sp) {
  3.             ContentValues cv = new ContentValues();
  4.     cv.clear();
  5.  
  6.     int sel_month = Integer.valueOf(sp.getString("pActivityMonth", String.valueOf(this.month))); //listvew works with strings, convert to int
  7.     int stored_new = 0; //default value
  8.     int stored_ren = 0; //default value
  9.  
  10.     Log.d(TAG, String.valueOf(sel_month));
  11.  
  12.     String[] col = { Database.C_MONTH, Database.C_QNEW, Database.C_QRENEW };
  13.     String[] arg = { String.valueOf(sel_month) };
  14.  
  15.     Cursor c = db.query(Database.RR_TABLE, col, Database.C_MONTH + "=?", arg, null, null, null);
  16.  
  17.     if (c.getCount()<1) { //New month, insert row
  18.         cv.put(Database.C_MONTH, sel_month);
  19.         db.insertWithOnConflict(Database.RR_TABLE, null, cv, SQLiteDatabase.CONFLICT_IGNORE);
  20.     } else { //row exists, get stored values
  21.         Log.d(TAG, "cursor count: " + String.valueOf(c.getCount()));
  22.         c.moveToFirst();
  23.         stored_new = c.getInt(c.getColumnIndex(Database.C_QNEW));
  24.         stored_ren = c.getInt(c.getColumnIndex(Database.C_QRENEW));
  25.         Log.d(TAG, "stored_new: " + String.valueOf(stored_new));
  26.     }
  27.  
  28.             //Change edittext preferences to stored values
  29.     editor.putString("pNewQuota", String.valueOf(stored_new));
  30.     editor.putString("pRenewQuota", String.valueOf(stored_ren));
  31.     editor.apply();
  32.     editor.commit();
  33.  
  34.  
  35.  
  36. }