tags:

views:

38

answers:

1

hello, I have a listview from an SQLDatabase using custom CursorAdaptor. I would like to go back to the activity that i used to create the items when i click on them in the listview.so that i can edit the entries. But nothing happen when i implement the OnItemClick method and the getItemId() on the CursorAdapter even though am not sure i am correct there. Here is my Code:

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

        Cursor c = adapter.retrieveRow(rowId); // retrieve row from Database
            Intent edit = new Intent(this,NewItem.class);
        edit.putExtra(DBAdapter.KEY_ID, rowId);
            edit.putExtra(DBAdapter.Title, c.getString(c.getColumnIndex(DBAdapter.Title)));
      edit.putExtra(DBAdapter.DATE, c.getString(c.getColumnIndex(DBAdapter.DATE)));
            startActivity(edit);
        }

public long getItemId(int id){
            return id;
        }
+1  A: 

I think you need to set an onItemClickListener on the Listview rather than trying to implement it in the Adapter class.

EXAMPLE:

mListView = (ListView)findViewbyId(R.id.whatever)
mListView.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View view, int position,
                    long rowId) {
                Cursor c = adapter.retrieveRow(rowId); // retrieve row from Database
                Intent edit = new Intent(this,NewItem.class);
                edit.putExtra(DBAdapter.KEY_ID, rowId);
                edit.putExtra(DBAdapter.Title, c.getString(c.getColumnIndex(DBAdapter.Title)));
                edit.putExtra(DBAdapter.DATE, c.getString(c.getColumnIndex(DBAdapter.DATE)));
                startActivity(edit);
            }
        });

Is this what you're doing?

QRohlf
QRohlf, that was exactly what i did but nothing happens. not even an error. By the way, i am extending a ListActivity if that will help.
manuelJ
I've edited my answer to include an example - this should work (This is how I handle all of my ListView clicks). If this *is* what you were doing, then I advise adding some logging to see what's going on, or using a breakpoint to see if it's actually getting called.
QRohlf
oops..my bad. i still implement my Listeners in the J2me style format, so i forgot to setOnClickListener(this). by the way, it works but when i click on an item, the entry before it gets returned and not the actual focused item. don't know why but am guessing that should not be too much trouble. Thanks once again
manuelJ