Silla Tan
Silla Tan

Reputation: 15

simple onListItemClick() arguments

I'm kind of new here so please bear with me if this seems like a stupid question. I'm currently using onListItemClick to retrieve the id of the selected ListItem. I'm quite confused about the difference between the int position and long id argument. Is it the same? Could someone kindly explain it please. Thank you in advanced.

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    Cursor c = ((SimpleCursorAdapter)l.getAdapter()).getCursor();
    c.moveToPosition(position);
    int _id = (int)c.getLong(0);
    //int _id = (int) id;
    String word_id = Integer.toString(_id);

    Toast.makeText(this, word_id, Toast.LENGTH_SHORT).show();
}

I was planning to use as simple button instead of the above method but I didn't know how to retrieve the ListView for the Activity.

Upvotes: 1

Views: 863

Answers (1)

ud_an
ud_an

Reputation: 4921

l   The ListView where the click happened
v   The view that was clicked within the ListView
position    The position of the view in the list
id  The row id of the item that was clicked

Upvotes: 3

Related Questions