0
我目前正試圖實現使用Adapter的ExtendedListView。 我實現視圖這樣一個活動:在另一個類中定義的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();
這是缺少