在可扩展列表视图中的组项内添加按钮时系统崩溃?
System crashes when added a button inside group item in an Expandable ListView?
我正在尝试向可扩展列表视图的组视图添加一个按钮。当我尝试下面的代码时,它不起作用(这段代码有一个文本视图,文本视图和按钮都不起作用),它崩溃了,我也上传了异常。我在下面的代码中显示了崩溃点。
任何人都可以告诉我我犯了什么错误或我需要在我的适配器中进行更改,
@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;
}
屏幕截图
使用 v
从 cart_list_group
布局访问所有视图。目前正在使用 convertView
,我由于 null
:
而导致问题
TextView editTv = (TextView) v.findViewById(R.id.lblsubtotccal);
我正在尝试向可扩展列表视图的组视图添加一个按钮。当我尝试下面的代码时,它不起作用(这段代码有一个文本视图,文本视图和按钮都不起作用),它崩溃了,我也上传了异常。我在下面的代码中显示了崩溃点。
任何人都可以告诉我我犯了什么错误或我需要在我的适配器中进行更改,
@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;
}
屏幕截图
使用 v
从 cart_list_group
布局访问所有视图。目前正在使用 convertView
,我由于 null
:
TextView editTv = (TextView) v.findViewById(R.id.lblsubtotccal);