JOSEMAFUEN JOSEMAFUEN - 3 months ago 15
Android Question

Modify xml attribute value Android

I have an xml like this in the

raw
folder

<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>


I read it on the
OnCreate
of the
activity
and with the attribute
abierto
I am building a
List<Boolean>
(
yes->true
,
no->false
).

The thing is that while the
Activity
is running, the list may be modified and some
false
may become
true
.

So, when the
Activity
is Stopped, I would want this changes to be saved, modifying in the
XML
the attributes "
abierto
" where "no" becomes "yes".

Answer

I think the the best solution here is use SQLite.

Create a table named premios like this, and use it to read, store, and modify values:

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