Hello lads!
What I mean with the title is, to simplify, that I've got a SQLite class, and from other activity I have implemented an AutoCompleteTextView. I want to fulfill some TextViews depending on what is chosen from the list.
So far I have been able to show the selection itself, but this is all straight because using autoCompleteCliente.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Overridepublic void onItemClick(AdapterView<?> parent, View view, int position, long id) {
I can do
String cliente = adapter.getItem(position);
My problem now is to get, using that String cliente, other info from the database. For that I have adapted my database class with the following method:
And then from my activity I try to use it:
But I am getting access error to Cursor position 0, but I don't understand what I am doing wrong
Any help will be appreciated, thanks in advance
What I mean with the title is, to simplify, that I've got a SQLite class, and from other activity I have implemented an AutoCompleteTextView. I want to fulfill some TextViews depending on what is chosen from the list.
So far I have been able to show the selection itself, but this is all straight because using autoCompleteCliente.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Overridepublic void onItemClick(AdapterView<?> parent, View view, int position, long id) {
I can do
String cliente = adapter.getItem(position);
My problem now is to get, using that String cliente, other info from the database. For that I have adapted my database class with the following method:
Java:
public Cursor getFromCliente (String cliente){
SQLiteDatabase db = this.getWritableDatabase();
//String where = "nombre_comercial = '" + cliente + "'";
Cursor cursor = db.query(true, TABLE_CLIENTES, CLIENTES_COLUMNS, "nombre_comercial='"+cliente+"'", null, null, null, null, null);
if (cursor != null) {
cursor.moveToFirst();
}
return cursor;
}
And then from my activity I try to use it:
Java:
//Catch selected client to fill fields
autoCompleteCliente.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//Getting the selected item to seek for other information of the client
String cliente = adapter.getItem(position);
Cursor cursorCliente = db.getFromCliente(cliente);
EditText sContacto = (EditText) findViewById(R.id.PTnombre);
EditText sDni = (EditText) findViewById(R.id.PTdni);
EditText sEmail = (EditText) findViewById(R.id.PTemail);
TextView sID = (TextView) findViewById(R.id.PTid);
sID.setText("3");
if( cursorCliente != null && cursorCliente.moveToFirst() ) {
sContacto.setText(cursorCliente.getString(cursorCliente.getColumnIndex("contactoNombre")));
//sDni.setText(cursorCliente.getColumnIndex("contactoDni"));
//sEmail.setText(cursorCliente.getColumnIndex("contactoEmail"));
}
}
});
But I am getting access error to Cursor position 0, but I don't understand what I am doing wrong

Any help will be appreciated, thanks in advance