I'm trying to do an insert test data in my database, but is not working.
Follow this video as a reference, but it did not work: https://www.youtube.com/watch?v=RPi7ueKwEXg
See below:
package com.bytemeta.bytenota.dominio;
import android.content.ContentValues;
import android.content.Context;
import android.database.*;
import android.database.sqlite.*;
import android.widget.ArrayAdapter;
import android.widget.*;
public class RepositorioCadastro{
private SQLiteDatabase conn;
public RepositorioCadastro(SQLiteDatabase conn){
this.conn = conn;
}
public void testeInserirCadastro(){
for (int i = 0; i < 10; i++){
ContentValues values = new ContentValues();
values.put("NOME", "THIAGO");
conn.insertOrThrow("CADASTRO", null, values);
}
}
}
public ArrayAdapter<String> buscaCadastro(Context context){
ArrayAdapter<String> adpCadastro = new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1);
Cursor cursor = conn.query("BYTENOTA_DB",null,null,null,null,null,null,null);
if (cursor.getCount() > 0) {
cursor.moveToFirst();
do {
String NOME = cursor.getString(1);
adpCadastro.add(NOME);
}while (cursor.moveToNext());
}
return adpCadastro;
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…