Where should I put code that detects when a row is clicked?
To detect a click anywhere on the line, use the OnItemClickListener in your activity.
To detect clicks in different regions on each row, use OnClickListeners in your getView() adapter.
You can also create a slightly faster adapter if you use the ViewHolder method. Google Talk TurboCharge Your UI discusses this and other good practices in detail.
Addition
How can I do this in my work?
ListActivities has a built-in OnListItemClick, the callback has a slightly different name: onListItemClick() . Use it like this:
@Override protected void onListItemClick (ListView l, View v, int position, long id) { Toast.makeText(this, "Clicked row " + position, Toast.LENGTH_SHORT).show(); }
source share