开发者

ListActivity extension doesn't execute onclick listener

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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜