Using the new Android persistence architecture, 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"
Answer.java
@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.
}
Answer.java
@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();
}
Activity.java
...
AppDatabase db = Room.databaseBuilder(getApplicationContext(),
AppDatabase.class, "database-name").build();
List<Resposta> respostas = metodoQuePovoaSuaLista();
for(Resposta r : respostas){
db.respostaDao().insert(r);
}
...
Any questions, let's talk, but the documentation is pretty cool Here