How to get onChildClick value from expandablelistview in android?

后端 未结 3 1472
陌清茗
陌清茗 2021-02-06 15:58

I am working on a project with parsing JSON from url to ExpandableListView. Depending on the \"status\" tag value (active or pending) , will be placing records accordingly to to

3条回答
  •  误落风尘
    2021-02-06 16:54

    Try This:

    @Override
    public boolean onContextItemSelected(MenuItem item) {
        ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) item.getMenuInfo();
    
        String title = ((TextView) info.targetView).getText().toString();
    
        int type = ExpandableListView.getPackedPositionType(info.packedPosition);
        System.out.println(" ----- " + type);
        if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
            int groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition);
            int childPos = ExpandableListView.getPackedPositionChild(info.packedPosition);
            Toast.makeText(this,title + ": Child " + childPos + " clicked in group "+ groupPos, Toast.LENGTH_SHORT).show();
            return true;
        } else if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
            int groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition);
            Toast.makeText(this, title + ": Group " + groupPos + " clicked",Toast.LENGTH_SHORT).show();
            return true;
        }
    
        return false;
    }
    

提交回复
热议问题