I have an activity that extends ListActivity and implementsOnScrollListener:
public class RecentItemsList extends Gen开发者_C百科ericListActivity implements OnScrollListener
and in this class I use a class that extends ArrayAdapter:
public class RecentItemAdapter extends ArrayAdapter<Item>
I'm trying to bind a callback when one of the items in the list is clicked by the user, but the callback isn't firing. Here's my code:
setListAdapter(adapter);
ListView lv = getListView();
lv.setOnScrollListener(RecentItemsList.this);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
// do some stuff
}
});
But the OnItemClick event is never fired, but the scroll events fire properly. Any ideas?
Try overriding your ListActivity's onListItemClick method instead:
@Override
public void onListItemClick( ListView parent, View v, int position, long id)
{
//...
}
We had a similar issue and resolved it by switching the type of activity we were extending. I think we used ListActivity and listen to onListItemClick.
For my specific case, there were focusable views in my row. apparently not possible: How to fire onListItemClick in Listactivity with buttons in list?
精彩评论