無法即時更改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