2016-08-24 81 views
2

我有一個這樣的XML在raw文件夾修改XML屬性值的Android

<premios> 
    <premio 
     corazones="5000" 
     nombrerecurso="foto" 
     carpetarecurso="drawable" 
     tipo="imagen" 
     abierto="yes" 
     /> 
    <premio 
     corazones="6000" 
     nombrerecurso="cuak" 
     carpetarecurso="raw" 
     tipo="audio" 
     abierto="no" 
    /> 
    <premio 
     corazones="7000" 
     nombrerecurso="video" 
     carpetarecurso="raw" 
     tipo="video" 
     abierto="no" 
    /> 
    <premio 
     corazones="7000" 
     nombrerecurso="video" 
     carpetarecurso="raw" 
     tipo="video" 
     abierto="yes" 
    /> 
</premios> 

我讀它的activityOnCreate與屬性abierto我建立一個List<Boolean>yes->trueno->false)。

問題是,當Activity正在運行時,該列表可能會被修改,並且某些false可能會變成true

因此,當Activity已停止時,我希望保存這些更改,在XML中修改屬性「abierto」,其中「否」變爲「是」。

+0

你不能!使用[共享首選項](https://developer.android.com/reference/android/content/SharedPreferences.html)或[SQLite](https://developer.android.com/reference/android/database/sqlite/SQLiteDatabase .html)。 – Abbas

回答

0

我認爲這裏最好的解決方案是使用SQLite。

創建一個名爲這樣premios表,並用它來讀取,存儲,並修改值:

CREATE TABLE PREMIOS(
    ID    INT PRIMARY KEY NOT NULL, 
    CORAZONES   INT, 
    NOMBRE_RECURSO TEXT, 
    CARPETA_RECURSO TEXT, 
    TIPO    TEXT, 
    ABIERTO   TEXT 
); 

Android開發者文檔和一個簡單的例子:

https://developer.android.com/training/basics/data-storage/databases.html

0

你不能更改任何資源文件!

正如文件documentationidsRaw文件夾中存儲爲public static final class R.raw在資源文件[R

所以,如果你需要改變在未來你的價值觀,你應該把它存放在SharedPreferenceSQLite