tags:

views:

25

answers:

1

Hello all, Good day, could you please help me look and this code and tell me what am doing wrong. I have a listview from a Cursor Adapter but when i click on a row, it returns back the row above it and not the target row clicked. which leads to if you click on the first row, it crashes with a "cursor out of bound exception". But when i add the c.moveToFirst() just before the intent invocation and i click on the first row, it just does nothing. Please here is the code:

public void onItemClick(AdapterView<?> parent, View view, int position, long rowId) {

   c = adapter.retrieveRow(rowId);

 Intent edit = new Intent(this,Item.class);
 edit.putExtra(DBAdapter.KEY_ID, rowId);
edit.putExtra(DBAdapter.NAME, c.getString(c.getColumnIndex(DBAdapter.NAME)));
edit.putExtra(DBAdapter.START_DATE, c.getString(c.getColumnIndex(DBAdapter.START_DATE)));
startActivityForResult(edit, ACTIVITY_EDIT);
}

and here is the database method that is being called:

public Cursor retrieveRow(long rowId) {
 String[] resultColumns = new String[] {NAME,START_DATE};
             Cursor row = db.query(true,DATABASE_TABLE, resultColumns, KEY_ID +"=" +rowId, null, null, null, null,null);
   if(row != null){
             row.moveToFirst();
   }
    return row;
   }

i tried changing it to a OnListItemSelected() but nothing happened, it did not return anything at all.I am using the new view and bind view method on the cursor adapter. thanks in advance.

A: 

Try to replace c = adapter.retrieveRow(rowId);

with c = adapter.getItem(position);

And comment out your retrieveRow method

Alex Volovoy
Hello, i seem to get an error when i use your suggestion. the method is not defined in my listview. I am using OnClickListener for the listview, or should i be using OnItemSelected listener? Thanks
Rexx
meant OnItemClickListener. sorry
Rexx
It should be OnItemClickListener(). But regardless of that getItem is not a method of the listener, but of the cursoradapter - you do use cursor adapter right ?
Alex Volovoy