Ejemplo n.º 1
0
 /** 添加提醒 */
 public static void addDrug(Context context, AnRemind new_drug) {
   if (new_drug == null) return;
   ArrayList<AnRemind> array = getDrug(context);
   int count = array.size();
   SharedPreferences.Editor prefs =
       context.getSharedPreferences(REMIND_SAVE_PATH, Activity.MODE_PRIVATE).edit();
   prefs.putInt("count", count + 1);
   prefs.putString("id" + 0, new_drug.getDrugId()); // 最新放在最前面
   prefs.putString("name" + 0, new_drug.getDrugName()); // 最新放在最前面
   prefs.putString("text" + 0, new_drug.getDrugText()); // 最新放在最前面
   AnRemind old_drug = null;
   for (int i = 0; i < count; i++) {
     old_drug = array.get(i);
     prefs.putString("id" + (i + 1), old_drug.getDrugId());
     prefs.putString("name" + (i + 1), old_drug.getDrugName());
     prefs.putString("text" + (i + 1), old_drug.getDrugText());
   }
   prefs.commit();
 }
Ejemplo n.º 2
0
 /** 重写提醒 */
 public static void writeDrug(Context context, ArrayList<AnRemind> array) {
   int count = array.size();
   SharedPreferences.Editor prefs =
       context.getSharedPreferences(REMIND_SAVE_PATH, Activity.MODE_PRIVATE).edit();
   prefs.putInt("count", count);
   AnRemind old_drug = null;
   for (int i = 0; i < count; i++) {
     old_drug = array.get(i);
     prefs.putString("id" + i, old_drug.getDrugId());
     prefs.putString("name" + i, old_drug.getDrugName());
     prefs.putString("text" + i, old_drug.getDrugText());
   }
   prefs.commit();
 }
Ejemplo n.º 3
0
 /** 修改提醒 */
 public static void alterDrug(Context context, AnRemind drug) {
   ArrayList<AnRemind> array = getDrug(context);
   int index = -1;
   for (int i = 0; i < array.size(); i++) {
     if (array.get(i).getDrugId().equals(drug.getDrugId())) index = i;
   }
   if (index != -1) {
     SharedPreferences.Editor prefs =
         context.getSharedPreferences(REMIND_SAVE_PATH, Activity.MODE_PRIVATE).edit(); // 更快
     prefs.putString("id" + index, drug.getDrugId());
     prefs.putString("name" + index, drug.getDrugName());
     prefs.putString("text" + index, drug.getDrugText());
     prefs.commit();
   }
 }