繁体   English   中英

上下文菜单不适用于可扩展列表视图项目

[英]Context Menu not working with Expandable list view item

我想为android中的可扩展列表子项实现上下文菜单。 我正在使用以下代码-

mExpandableListView.setOnItemLongClickListener(new OnItemLongClickListener() {

            @Override
            public boolean onItemLongClick(AdapterView<?> arg0, View view,
                    int arg2, long arg3) {

                int type =ExpandableListView.getPackedPositionType(arg3);

                int groupPos = ExpandableListView.getPackedPositionGroup(arg3);
                int childPos = ExpandableListView.getPackedPositionChild(arg3);

                if(type==ExpandableListView.PACKED_POSITION_TYPE_CHILD){
                    registerForContextMenu(getExpandableListView().getChildAt(arg2));
                    Toast.makeText(getApplicationContext(), "Hello Hello"+"  "+groupPos+" "+childPos, 0).show();
                }
                return true;
            }
        });

@Override
    public void onCreateContextMenu(ContextMenu menu, View v,
            ContextMenuInfo menuInfo) {
        // TODO Auto-generated method stub
        super.onCreateContextMenu(menu, v, menuInfo);

        ExpandableListView.ExpandableListContextMenuInfo info =
            (ExpandableListView.ExpandableListContextMenuInfo) menuInfo;

        int type =
            ExpandableListView.getPackedPositionType(info.packedPosition);

        int group =
            ExpandableListView.getPackedPositionGroup(info.packedPosition);

        int child =
            ExpandableListView.getPackedPositionChild(info.packedPosition);


        menu.setHeaderTitle("CCM");
        menu.setHeaderIcon(R.drawable.ic_launcher);
        menu.add(0, v.getId(), 0, "HelloCCM");      

    }

但是根本没有打开上下文菜单。

请帮我弄清楚

你加了吗

registerForContextMenu(mExpandableListView);

初始化视图时?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM