Android 在另一个类中定义的ExtendedListView不可见
我目前正在尝试实现一个使用适配器的ExtendedListView。 我在活动中实现了如下视图:Android 在另一个类中定义的ExtendedListView不可见,android,view,Android,View,我目前正在尝试实现一个使用适配器的ExtendedListView。 我在活动中实现了如下视图: groupView = new GroupView((ExpandableListView) findViewById(R.id.groupView), getApplicationContext()); GroupView的构造函数如下所示: public GroupView(ExpandableListView list, Context c) { context = c; e
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());
}
}
}
}
公共组视图(可扩展列表视图列表,上下文c)
{
上下文=c;
expandableListView=列表;
适配器=新的GroupViewAdapter(上下文,
新建ArrayList(),
新的ArrayList());
expandableListView.setAdapter(适配器);
}
适配器如下所示:
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());
}
}
}
}
公共类GroupViewAdapter扩展了BaseExpandableListAdapter
{
私人语境;
私有ArrayList组;
私人ArrayList儿童;
公共GroupViewAdapter(上下文、ArrayList组、,
ArrayList(儿童)
{
this.context=上下文;
这个组=组;
这个。孩子=孩子;
}
/**
*获取包含参与者列表的组的完整结构(映射)
*每个)并绘制它
*/
public void updateView()
{
Map groupMap=GroupManager.getInstance()
.getGroups();
对于(Map.Entry:groupMap.entrySet())
{
String groupName=entry.getKey();
ParticipantGroup组=entry.getValue();
如果(!groups.contains(group))//如果该组尚不存在,则会创建该组
{
组。添加(组);
}
int index=组。indexOf(组);
if(children.size()
当通过适配器时,我看到组被添加到它们应该添加的地方,但我在模拟器中实际上看不到任何东西。这只是一个白色的背景。你能告诉我我缺少了什么来让它真正可见吗
编辑:好的,这是一个简单的
适配器。notifyDataSetChanged()缺少的代码>好的,这是一个简单的适配器。notifyDataSetChanged()缺少的代码>(在调用updateView()
之后)