Im using a listView to show a DataBase data (3 fields but just shows the name) and when I click 1 item, an AlertDialog shows up and I can see the other fields of that row, Im using a cursor to select the data and then just pass the strings that I want, but every time I press one I get a different element that expected, I know I could just make a query of the row I want to get, but Im so bad at SQLite so I rather doing it this way, here is the code:
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
Cursor crs = db.rawQuery("SELECT * FROM Usuarios", null);
crs.moveToPosition(position);
// get prompts.xml view
LayoutInflater li = LayoutInflater.from(context);
View promptsView1 = li.inflate(R.layout.dialog1, null);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
context);
// set prompts.xml to alertdialog builder
alertDialogBuilder.setView(promptsView1);
final TextView nam = (TextView) promptsView1
.findViewById(R.id.name1);
nam.setText(crs.getString(0));
final TextView ape = (TextView) promptsView1
.findViewById(R.id.apellido2);
ape.setText(crs.getString(1));
final TextView loc = (TextView) promptsView1
.findViewById(R.id.loc1);
loc.setText(crs.getString(2));
// set dialog message
alertDialogBuilder
.setCancelable(true);
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
//cursor = null;
}
});
Any help using this method or the one (Query sentence) would be appreciated
Aucun commentaire:
Enregistrer un commentaire