我已经实现了ExpandableListView
和BaseExpandableListAdapter
。 我想显示GroupObjects的列表。 每GroupObject(在ExpandableList顶级项目)有3个ChildObjects(在ExpandableList儿童项目)的ArrayList。
我现在用的是viewHolder模式。 该GroupObjects正确显示。 有一次,我展开第一个GroupObject, getChildView()
被调用3次,并正确显示其ChildObjects。
但只要我展开另一个GroupObject, getChildView()
返回第一个GroupObject的ChildObjects。 由于第二呼叫convertView不为空,它总是返回相同的ChildObjects。
下面是一些代码:
@Override
public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild,
View convertView, ViewGroup parent) {
final ChildObject childobject = (ChildObject)getChild(groupPosition, childPosition);
ChildViewholder childViewholder;
if (convertView == null) {
childViewholder = new ChildViewholder();
LayoutInflater inflater = (LayoutInflater)context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (!childobject.isReserved()) {
convertView = inflater.inflate(R.layout.childobject_free,
parent, false);
childViewHolder.layout = (RelativeLayout)convertView
.findViewById(R.id.childobject_free_layout);
} else {
final Reservation reservation = childobject.getReservation();
convertView = inflater.inflate(
R.layout.childobject_reserved, parent, false);
childViewHolder.layout = (RelativeLayout)convertView.findViewById(R.id.reserved_layout);
childViewHolder.reservationImage = (ImageView)convertView.findViewById(R.id.reservationImage);
childViewHolder.reservationName = (TextView)convertView.findViewById(R.id.reservationName);
childViewHolder.buttonFinish = (ImageButton)convertView
.findViewById(R.id.finishButton);
childViewHolder.buttonCancel = (ImageButton)convertView
.findViewById(R.id.cancelButton);
childViewHolder.progressBar = (ProgressBar)convertView
.findViewById(R.id.reservationProgress);
childObject.getTimer().setProgressBar(childViewHolder.progressBar);
childViewHolder.reservationName.setText(reservation.getName());
childViewHolder.reservationImage.setImageBitmap(reservation.getBitmap());
childViewHolder.buttonFinish.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
DrawerClickHandler.finishReservation(reservation);
}
});
childViewHolder.buttonCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DrawerClickHandler.cancelReservation(reservation);
}
});
}
convertView.setTag(childViewholder);
}else{
childViewholder = (ChildViewholder)convertView.getTag();
}
childViewHolder.groupPosition = groupPosition;
childViewHolder.childPosition = childPosition;
return convertView;
}
该convertView只对前3调用空getChildView()
让我知道如果你需要更多的代码。
任何帮助表示赞赏。