Using the new Android persistence file, Room :
First you need to import dependencies:
build.Gradle
allprojects {
repositories {
jcenter()
maven { url 'https://maven.google.com' }
}
}
compile "android.arch.persistence.room:runtime:1.0.0-alpha3"
annotationProcessor "android.arch.persistence.room:compiler:1.0.0-alpha3"
Java response.
@Entity
public class Resposta {
@PrimaryKey
private int id;
@ColumnInfo(name = "questao")
private String questao
@ColumnInfo(name = "is_check")
private Boolean isCheck;
// Getters and setters are ignored for brevity,
// but they're required for Room to work.
}
Java response.
@Dao
public interface RespostaDao {
@Query("SELECT * FROM resposta")
List<User> getAll();
@Insert
void insert(Resposta resposta);
@Delete
void delete(Resposta resposta);
}
Appdatabase.java
@Database(entities = {Resposta.class}, version = 1)
public abstract class AppDatabase extends RoomDatabase {
public abstract RespostaDao respostaDao();
}
Java activity.
...
AppDatabase db = Room.databaseBuilder(getApplicationContext(),
AppDatabase.class, "database-name").build();
List<Resposta> respostas = metodoQuePovoaSuaLista();
for(Resposta r : respostas){
db.respostaDao().insert(r);
}
...
Any doubt we talked, but the documentation is very cool Here
If you have
date
this is not Sqlite. Just like the date, you will have to serialize in string and record undo.– Maniero
Take a look at the new Android data persistence architecture, it might help you. Try using Room. If I want to put an example there, hug!! https://developer.android.com/topic/libraries/architecture/room.html
– Arthur Stapassoli
@Arthurcordovastapassoli would like you to give an example, please?
– Lucas Charles
Sure, I’ll ride here and post
– Arthur Stapassoli
When one starts badly the tendency is for problems to multiply. If one were to implement the suggestion given in this reply would only have to keep a value.
– ramaral
@ramaral but anyway I will have to use this method. I have a listview with 3 Radiobutton in each position of listview. And I need to save in the bank the selection of each Listview Radiobutton.
– Lucas Charles
Are you no longer saving the other information? Just save this one more (another field in the table).
– ramaral
@ramaral yes yes, but the others are a unique field, as name, type and hired. In this table field I need to save the answers.
– Lucas Charles
You can’t understand it. It’s better to ask another question in full detail. What is an answer? It makes no sense to say "they are a unique field, as name, type and hired" and "In this field of the table I need to save the answers".
– ramaral