在另一个类中定义的 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();
丢失了
I'm currently trying to implement an ExtendedListView that uses an Adapter.
I'm implementing the View like this in an activity:
groupView = new GroupView((ExpandableListView) findViewById(R.id.groupView), getApplicationContext());
The constructor of GroupView looks like this:
public GroupView(ExpandableListView list, Context c)
{
context = c;
expandableListView = list;
adapter = new GroupViewAdapter(context,
new ArrayList<ParticipantGroup>(),
new ArrayList<ArrayList<Participant>>());
expandableListView.setAdapter(adapter);
}
The adapter looks like this:
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());
}
}
}
}
When going trough the adapter I see the groups get added where they're supposed to, but I can't actually see anything in the emulator. It's just a white background. Can you tell me what I'm missing to actually make this visible?
Edit: Okay, it was a simple adapter.notifyDataSetChanged();
that was missing
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,这是一个简单的
adapter.notifyDataSetChanged();
丢失了(调用updateView()
后)Okay, it was a simple
adapter.notifyDataSetChanged();
that was missing (After callingupdateView()
)