0
I need to save in a list the names of the user table and save them in an Arraylist. I did as follows:
public List<String> buscarUsuarios() {
List<String> nomes = new ArrayList<String>();
String selectQuery = "select nome from usuarios";
Cursor cursor = db.rawQuery(selectQuery, null);
if (cursor.getCount() > 0) {
cursor.moveToFirst();
do {
cursor.moveToFirst();
String nomeString = cursor.getString(cursor.getColumnIndex("nome"));
StringBuilder conversor = new StringBuilder();
conversor.append(nomeString);
nomes.add(conversor.toString());
} while (cursor.moveToNext());
}
return nomes;
}
But it’s looping endlessly Someone can help me?
You are always moving to the first, in all the loops. So, it will never reach the end
– Artur Trapp
Ours is the lack of coffee. THANK YOU!
– Lucas Charles
although remove works, it would be best to Voce position it outside the loop.
– Armando Marques Sobrinho