在另一个类中定义的 ExtendedListView 是不可见的

发布于 2024-11-03 14:24:16 字数 2372 浏览 1 评论 0原文

我目前正在尝试实现一个使用适配器的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

提赋 2024-11-10 14:24:16

好吧,这是一个简单的 adapter.notifyDataSetChanged(); 丢失了(调用 updateView() 后)

Okay, it was a simple adapter.notifyDataSetChanged(); that was missing (After calling updateView())

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文