无法即时更改strings.xml文件。你可以做的是抽象字符串聚集。
class YourUtilites {
static HashMap<String, String> dbCache = new HashMap<String, String>();
public static String getString(Context context, String key, String defaultID) {
String value = null;
value = dbCache.get(key);
if (value == null) {
// Check if the key exists in the database
String value = db.somedbFunctionToGetString(key);
if (value != null) {
dbCache.put(key, value);
}
}
if (value == null) {
// If value is not in the database, resort to the default value
value = context.getResources().getString(defaultID);
}
return value;
}
}
然后你就可以在textviews使用这样
textView.setText(YourUtilities.getString("dbKey", R.id.defaultValue1, this);
textView2.setText(YourUtilities.getString("dbKey2", R.id.defaultValue2, this);
...
这样你就可以更新你的分贝值,并将它立刻显示出来。当您更新数据库值时,不要忘记清除dbCache。这个解决方案显然不用说db访问速度慢,所以记住这一点。
希望这会有所帮助。
不可能。当然,除非你的应用反编译自己>用新值覆盖strings.xml>重新编译并将自身复制到'/ data/app /',然后强制重新启动目标。 – ozbek
好吧,那只是我的一个想法,但其他任何方式呢? – possenH4lt3r