在Expandable ListView中的组项目中添加按钮后,系统崩溃了?

时间:2015-04-08 10:43:31

标签: android button expandablelistview textview

我尝试将按钮添加到可展开列表视图的组视图中。当我尝试下面的代码时,它没有工作(这段代码有textview,textview和按钮都没有工作),它崩溃了,我也上传了异常。我在下面的代码中显示了崩溃点。

任何人都可以告诉我我所犯的错误或我需要在我的适配器中进行的更改,

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded,
            View convertView, ViewGroup parent) {

        View v = convertView;

        if (v == null) {
            LayoutInflater inflater = (LayoutInflater) _context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = inflater.inflate(R.layout.cart_list_group, parent, false);
        }

        TextView groupName = (TextView) v.findViewById(R.id.lblListHeader);
        TextView groupQty = (TextView) v.findViewById(R.id.lbl_qty);
        TextView groupSubtotal = (TextView) v.findViewById(R.id.lblsubtotal);

        Product cat = _cartList.get(groupPosition);

        groupName.setText(cat.description);
        groupQty.setText(String.valueOf(cat.quantity));
        groupSubtotal.setText(Double.toString(cat.subTotal));

        TextView editTv = (TextView) convertView.findViewById(R.id.lblsubtotccal); //crashes here
        editTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent next = new Intent(_context, ActivityCustomize.class);

                _context.startActivity(next);
                ((Activity) _context).overridePendingTransition(
                        R.anim.slide_in_right, R.anim.slide_out_left);
            }
        });

        return v;
    }

屏幕截图

enter image description here

1 个答案:

答案 0 :(得分:1)

使用v访问cart_list_group布局中的所有视图。目前正在使用由convertView引起问题的null

    TextView editTv = (TextView) v.findViewById(R.id.lblsubtotccal);