我有一个对象列表,我想用这些对象的数据填充ExpandableListView。我想在ExpandableListView的父级中显示对象的一个属性,并在ExpandableListView的子级中显示对象的另一个属性。任何人都可以告诉我我该怎么做,我的代码就像这些;
当我使用这些代码时,只有一个父行显示在ExpandableList上,bu列表有多个对象。
public class textExpAdapter extends BaseExpandableListAdapter {
public List<textexplain> tmpTextExp;
public Context context;
public LayoutInflater inflater;
@Override
public int getGroupCount() {
return extCrmActions.size();
}
public textExpAdapter (Context context, List<textexplain> tmpTextExp)
{
this.context = context;
this.tmpTextExp= tmpTextExp;
}
@Override
public int getChildrenCount(int groupPosition) {
return 1;
}
@Override
public Object getGroup(int groupPosition) {
return tmpTextExp.get(groupPosition);
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return tmpTextExp.get(childPosition);
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View view, ViewGroup parent) {
textexplain action = (textexplain) getGroup(groupPosition);
if(view == null)
{
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.crmactions_elv_head,null);
}
final TextView txtCrmActionHeaderClm1 = (TextView)view.findViewById(R.id.txtCrmActionHeaderClm1);
final TextView txtCrmActionHeaderClm2 = (TextView)view.findViewById(R.id.txtCrmActionHeaderClm2);
SimpleDateFormat sdFormat = new SimpleDateFormat("dd.MM.yyyy");
txtCrmActionHeaderClm1.setText(sdFormat.format(action.ACTIONDATE));
txtCrmActionHeaderClm2.setText(action.STEXT);
return view;
}
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View view, ViewGroup parent) {
textexplain action = (textexplain) tmpTextExp.get(groupPosition);
if(view==null)
{
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.crmactions_elv_bottom, null);
}
final TextView txtCrmActionBottomText = (TextView)view.findViewById(R.id.txtCrmActionBottomText);
txtCrmActionBottomText.setText(action.LTEXT);
return view;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}