0
How to make the SQLITE Cursor, make the variables not stop at the last value ? I made a Setadapter to which he lists all the Listview data, so far so good, but when I put some variable that is inside WHILE, it prints the last value, and I need it to show me all the values in the Log. i(); below the code:
//Classe do select do SQLITE
public class Testesqlite extends Tela{
static String testenome,testesobrenome,testenascimento;
public void gambi(){
Cursor c = bancosqlite.rawQuery("SELECT nome,sobrenome,nascimento FROM tabelateste",null);
while (c.moveToNext()) {
testenome = c.getString(c.getColumnIndex("nome")).trim();
testesobrenome = c.getString(c.getColumnIndex("sobrenome")).trim();
testenascimento = c.getString(c.getColumnIndex("nascimento")).trim();
}
}
}
//Ação ao clicar em um item do ListView
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int posicao, long id) {
posi = parent.getItemAtPosition(posicao).toString();
Testesqlite gambb = new Testesqlite();
gambb.gambi();
if (posi.equals(testenome)) {
Intent teste = new Intent(Testing.this, Tela_teste.class);
startActivity(teste);
}
//Aqui ele me mostra corretamente a posição
//do item clicado, só que o da váriavel "testenome" que
//fica dentro do while fica só no
//no ultimo, fica toda hora printando o ultimo
//e não outros valores ; /
Log.i("Clicado", posi + "\t" + testenome);
}
});
}
The first name is the variable "posi" and the second name is the "testenome" which always shows me the last value, I do not know why .
NOTE: When clicking on the Listview item containing the name "Testeaaa", it opens another Activity without problems, but others do nothing .
Message on the logcat
12-08 12:18:24.680 26825-26825/br.com.kappauni.test I/Clicado Diego Kappaun Testeaaa 12-08 12:18:29.960 26825-26825/br.com.kappauni.test I/Clicked Diella Heckler granella Testeaaa 12-08 12:18:38.960 26825-26825/br.com.kappauni.test I/Clicked Testeaaa Testeaaa
The while traverse the entire cursor, from the first record to the last, assigning the values of the fields always to the same variables. So the variables will have the value of the last record. To help we need to know what the purpose of your code is.
– ramaral
I need that when you click on any of the names, it recovers the value of the bank that was clicked on. When I click on my name and my girlfriend’s name it doesn’t work, only when I click on "Testeaaa" it opens the screen normally, I just need to make it work to continue the project. I edited the post and put 2 images for viewing and sorry for the bad editing.
– Diego Kappaun