Come posso ottenere il valore della colonna successiva non la nuova riga?
Sto usando listview per visualizzare le informazioni dell'utente selezionato dallo spinner.
Cosa appare: Nome, Nome, Nome
Dovrebbe essere invece: Nome, Cognome, Email, ecc.
Sto pensando di aggiungere i ++ ma sembra non funzionare
public void myMethod(String user) {
ArrayList<String> theList = new ArrayList<>();
Cursor data = db.getListViewAccountrequestinfo();
if (data.getCount() == 0) {
} else {
while (data.moveToNext()) {
theList.add( data.getString(0) );
ListAdapter listAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, theList);
lvinfo.setAdapter(listAdapter);
}
}
}
risposte:
0 per risposta № 1Listview dovrebbe visualizzare le righe nel database, non le colonne.
Perché
data.getString()
accetta il parametro comeint columnIndex
quindi quando aumenti il suo valore (columnIndex), ti darà Colonna successiva valore non la nuova riga.
Fare riferimento Cursor.getString ()
0 per risposta № 2
L'ho già capito. Ecco il mio nuovo codice di lavoro dopo 4 ore LOL
public void myMethod() {
ArrayList<String> theList = new ArrayList<>();
Cursor data = db.getListViewAccountrequestinfo(spnpending.getSelectedItem().toString());
if (data.getCount() == 0) {
} else {
if (data.moveToFirst()) {
do {
theList.add("Username: " + spnpending.getSelectedItem());
theList.add("First name: " + data.getString(1));
theList.add("Last name: " + data.getString(2));
theList.add("Contact: " + data.getString(3));
theList.add("Email: " + data.getString(4));
ListAdapter listAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, theList);
lvinfo.setAdapter(listAdapter);
} while (data.moveToNext());
}
}