开发者

Possible to have both a context menu and default click behavior on ExpandableListView group items?

开发者 https://www.devze.com 2023-02-09 18:03 出处:网络
Is it possible to have both a context menu and default click behavior on ExpandableListView group items?

Is it possible to have both a context menu and default click behavior on ExpandableListView group items?

I tried this and found that once I overrode onCreateContextMenu in the activity that contained the ExpandableListView, the group views would no longer respond to clicks. They wouldn't highlight when (short) pressed and they wou开发者_JAVA技巧ldn't expand.


The solution is to let the Activity containing the ExandableListView know that it should handle context menu creation for the view. This can be accomplished as follows, most likely in the overridden onCreate method of the Activity:

ExpandableListView listView = (ExpandableListView) findViewById( R.id.list );
registerForContextMenu( listView );

Then, in the Activity, be sure to override onCreateContextMenu, where you'll configure the context menu that gets shown.

0

精彩评论

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

关注公众号