在我的可扩展列表视图中,有些有子视图,有些没有子视图。没有子视图的GroupView包含文本视图和按钮。单击按钮时,我需要通过intent将textview的数据传递给下一个活动。现在我的问题是,我无法在groupview的按钮上设置onclick事件,因为它没有子级,而且我还需要groupposition。
以下是主Java文件中的CLICKISTENER代码:

expandableListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
        @Override
        public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
            switch (groupPosition) {
                case 0:
                    Log.d(">>>", "" + groupPosition);
                    break;
                case 1:
                    Log.d(">>>", "" + groupPosition);
                    break;
                case 2:
                    Log.d(">>>", "" + groupPosition);
                    break;
                case 3:
                    Log.d(">>>", "" + groupPosition);
                    break;
            }
            return false;
        }
    });

这是我的适配器代码:
public View getGroupView(int groupPosition, boolean isExpanded,
                         View convertView, ViewGroup parent) {
    groupIndex = groupPosition;
    QuotedListGroup group = (QuotedListGroup) getGroup(groupPosition);
    if (convertView == null) {
        LayoutInflater inf = (LayoutInflater) context
                .getSystemService(context.LAYOUT_INFLATER_SERVICE);
        convertView = inf.inflate(R.layout.activity_expandable_listview, null);
    }

    if(groupPosition%2 == 0) {
        convertView.findViewById(R.id.part_1).setVisibility(View.VISIBLE);
        convertView.findViewById(R.id.part_2).setVisibility(View.GONE);
        //Other code..
    } else {
        convertView.findViewById(R.id.part_1).setVisibility(View.GONE);
        convertView.findViewById(R.id.part_2).setVisibility(View.VISIBLE);
        //Other code..
    }
    return convertView;
}

实际上,我需要在同一个expandablelistview中为偶数和奇数组显示两种不同的布局。
非常感谢您的帮助!

最佳答案

这样地

elv.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
        @Override
        public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {

            Bundle bundle;
            switch (groupPosition) {
               case 0:
               //add your code here

            return false;
        }
    });

10-07 21:00