Here you can find the source of updatePrefValueByModel(SharedPreferences pref, String key, String thisModel, String targetModel, Object targetModelValue, Object notTargetModelValue)
public static Object updatePrefValueByModel(SharedPreferences pref, String key, String thisModel, String targetModel, Object targetModelValue, Object notTargetModelValue)
//package com.java2s; import java.util.Locale; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; public class Main { public static Object updatePrefValueByModel(SharedPreferences pref, String key, String thisModel, String targetModel, Object targetModelValue, Object notTargetModelValue) { Object value;/*from www . j a v a2 s .co m*/ String mdl = "#" + thisModel.toUpperCase(Locale.US) + "#"; if (targetModel != null && targetModel.indexOf(mdl) != -1) { value = targetModelValue; } else { value = notTargetModelValue; } if (value != null) { Editor edit = pref.edit(); if (value instanceof String) { edit.putString(key, (String) value); } else if (value instanceof Boolean) { edit.putBoolean(key, (Boolean) value); } edit.commit(); } return value; } public static int indexOf(String[] datas, String val) { if (val != null) { for (int i = 0; i < datas.length; i++) { if (datas[i].equals(val)) { return i; } } } return -1; } }