我目前正在尝试实现使用适配器的ExtendedListView。 我正在一项活动中实现这样的视图:
groupView = new GroupView((ExpandableListView) findViewById(R.id.groupView), getApplicationContext());
GroupView的构造函数如下所示:
public GroupView(ExpandableListView list, Context c)
{
context = c;
expandableListView = list;
adapter = new GroupViewAdapter(context,
new ArrayList<ParticipantGroup>(),
new ArrayList<ArrayList<Participant>>());
expandableListView.setAdapter(adapter);
}
适配器看起来像这样:
public class GroupViewAdapter extends BaseExpandableListAdapter
{
private Context context;
private ArrayList<ParticipantGroup> groups;
private ArrayList<ArrayList<Participant>> children;
public GroupViewAdapter(Context context, ArrayList<ParticipantGroup> groups,
ArrayList<ArrayList<Participant>> children)
{
this.context = context;
this.groups = groups;
this.children = children;
}
/**
* Gets the complete structure (Map of groups with a list of participants
* each) and draws it
*/
public void updateView()
{
Map<String, ParticipantGroup> groupMap = GroupManager.getInstance()
.getGroups();
for (Map.Entry<String, ParticipantGroup> entry : groupMap.entrySet())
{
String groupName = entry.getKey();
ParticipantGroup group = entry.getValue();
if(!groups.contains(group)) //In case the group does not exist yet, it gets created
{
groups.add(group);
}
int index = groups.indexOf(group);
if (children.size() < index + 1) {
children.add(new ArrayList<Participant>());
}
ArrayList<Participant> participants = group.getParticipants();
Iterator<Participant> itr = participants.iterator();
while(itr.hasNext())
{
children.get(index).add(itr.next());
}
}
}
}
当通过适配器时,我看到组被添加到它们应该的位置,但我实际上无法在模拟器中看到任何内容。它只是一个白色背景。你能告诉我我真正想要的是什么吗?
修改:好的,这是一个简单的adapter.notifyDataSetChanged();
缺少
答案 0 :(得分:0)
好的,这是一个简单的adapter.notifyDataSetChanged();
缺少(调用updateView()
后)