Olá! Sempre que eu cadastro o primeiro aluno, ele não aparece na lista. Então se eu cadastro um segundo aluno, ele aparece sozinho na lista e com o ID 2 (então o primeiro aluno está no banco, só não está sendo exibido).
Segue código:
AlunoDAO - buscaAluno()
public List<Aluno> buscaAlunos() {
String sql = "select * from Alunos";
SQLiteDatabase db = getReadableDatabase();
Cursor c = db.rawQuery(sql, null);
List<Aluno> alunos = new ArrayList<Aluno>();
while(c.moveToNext()) {
Aluno aluno = new Aluno();
aluno.setId(c.getLong(c.getColumnIndex("id")));
aluno.setNome(c.getString(c.getColumnIndex("nome")));
aluno.setEndereco(c.getString(c.getColumnIndex("endereco")));
aluno.setTelefone(c.getString(c.getColumnIndex("telefone")));
aluno.setSite(c.getString(c.getColumnIndex("site")));
aluno.setNota(c.getDouble(c.getColumnIndex("nota")));
alunos.add(aluno);
}
c.close();
return alunos;
}
ListaAlunosActivity - onCreate()
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_lista_alunos);
AlunoDAO dao = new AlunoDAO(this);
List<Aluno> alunos = dao.buscaAlunos();
dao.close();
ListView listaAlunos = (ListView) findViewById(R.id.lista_alunos);
ArrayAdapter<Aluno> adapter = new ArrayAdapter <Aluno> (this, android.R.layout.simple_list_item_1, alunos);
listaAlunos.setAdapter(adapter);
[......]