1. Check out our companion app, Forums for Android! Download from Google Play

cursor not returning correct row position in ListView

Discussion in 'Application Development' started by motoko, Sep 14, 2010.

  1. motoko

    motoko Member
    Thread Starter

    Jun 26, 2010
    Hello all, could you please help me look and this code and tell me what am doing wrong. I have a listview that is populated through a Cursor Adapter but when i click on a row, it returns back the row above it and not the target row clicked. and if i click on the first row, it just crashes with a "cursor out of bound exception". Here is the code:

    Code (Text):
    1. public void onItemClick(AdapterView<?> parent, View view, int position, long rowId) {
    3.          c = adapter.retrieveRow(rowId);
    5.  Intent edit = new Intent(this,Item.class);
    6.     edit.putExtra(DBAdapter.KEY_ID, rowId);
    7. edit.putExtra(DBAdapter.NAME, c.getString(c.getColumnIndex(DBAdapter.NAME)));
    8. edit.putExtra(DBAdapter.START_DATE, c.getString(c.getColumnIndex(DBAdapter.START_DATE)));
    9. startActivityForResult(edit, ACTIVITY_EDIT);
    10. }
    and this is the database method that is being called:

    Code (Text):
    1. public Cursor retrieveRow(long rowId) {
    2.  String[] resultColumns = new String[] {NAME,START_DATE};
    3.              Cursor row = db.query(true,DATABASE_TABLE, resultColumns, KEY_ID +"=" +rowId, null, null, null, null,null);
    4.          if(row != null){
    5.                 row.moveToFirst();
    6.          }
    7.           return row;
    8.       }
    i have tried changing it to a OnListItemSelected() but nothing happens.I am using the new view and bind view method on the cursor adapter. Please Help.


Share This Page