当我展开ExpandableListView的项目时,我想显示一个ListView。这是ExpandableListView的适配器:
public class ExpandableListAdapterDay extends BaseExpandableListAdapter{
private Activity _context;
private ArrayList<String> _listDataHeader; // header titles
private HashMap<String, ArrayList<DataDay>> _listDataChild;
private static class ViewHolderChild {
public final ListView listDay;
public ViewHolderChild(ListView listDay) {
this.listDay = listDay;
}
}
private static class ViewHolderGroup {
public final TextView textHeader;
public ViewHolderGroup(TextView textHeader) {
this.textHeader = textHeader;
}
}
public ExpandableListAdapterDay(Activity context, ArrayList<String> listDataHeader,
HashMap<String, ArrayList<DataDay>> listChildData) {
this._context = context;
this._listDataHeader = listDataHeader;
this._listDataChild = listChildData;
}
@Override
public int getGroupCount() {
// TODO Auto-generated method stub
return this._listDataHeader.size();
}
@Override
public int getChildrenCount(int groupPosition) {
// TODO Auto-generated method stub
return this._listDataChild.get(this._listDataHeader.get(groupPosition)).size();
}
@Override
public Object getGroup(int groupPosition) {
// TODO Auto-generated method stub
return this._listDataHeader.get(groupPosition);
}
@Override
public Object getChild(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return this._listDataChild.get(this._listDataHeader.get(groupPosition));
//.get(childPosition);
}
@Override
public long getGroupId(int groupPosition) {
// TODO Auto-generated method stub
return groupPosition;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return childPosition;
}
@Override
public boolean hasStableIds() {
// TODO Auto-generated method stub
return false;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
TextView textHeader;
String strDataHeader = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_group_day, null);
textHeader = (TextView) convertView.findViewById(R.id.textHeaderDay);
convertView.setTag(new ViewHolderGroup(textHeader));
} else {
ViewHolderGroup viewHolder = (ViewHolderGroup) convertView.getTag();
textHeader = viewHolder.textHeader;
}
textHeader.setTypeface(null, Typeface.BOLD);
textHeader.setText(strDataHeader);
return convertView;
}
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ListView listDay;
final ArrayList<DataDay> arrayDay = (ArrayList<DataDay>) getChild(groupPosition, childPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_item_day, null);
listDay = (ListView) convertView.findViewById(R.id.listDay);
convertView.setTag(new ViewHolderChild(listDay));
} else {
ViewHolderChild viewHolder = (ViewHolderChild) convertView.getTag();
listDay = viewHolder.listDay;
}
AdapterDataDay adapter = new AdapterDataDay (_context, arrayDay);
listDay.setAdapter(adapter);
return convertView;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return true;
}
}
当我展开ExpandableListView时,这是我想要显示的ListView的适配器:
public class AdapterDataDay extends BaseAdapter{
protected Context activity;
protected ArrayList<DataDay> arrayItem;
private static class ViewHolder {
public TextView textDate;
public TextViewEx textItem;
public ViewHolder() {
}
}
public AdapterDatosOraciones(Context activity, ArrayList<DataDay> items) {
this.activity = activity;
this.arrayItem = items;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return arrayItem.size();
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return arrayItem.get(arg0);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return arrayItem.get(position).getId();
}
@SuppressLint("NewApi")
@Override
public View getView(int position, View convertView, ViewGroup arg2) {
ViewHolder holder;
if(convertView == null){
LayoutInflater inf = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inf.inflate(R.layout.list_item_day_listview, null);
holder = new ViewHolder();
holder.textDate = (TextView) convertView.findViewById(R.id.textDate);
holder.textItem = (TextViewEx) convertView.findViewById(R.id.textItem);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
DataDay data = arrayItem.get(position);
holder.textDate.setText(data.strDate);
holder.textItem.setText(data.strItem, true);
return convertView;
}
}
问题是,当我展开ExpandableListView的项目时,ListView的所有项目都是相同的,在所有ListView中始终显示相同的项目。我做错了什么?
提前致谢。