【问题标题】:Can an ExpandableListView be embedded in another layout?ExpandableListView 可以嵌入到另一个布局中吗?
【发布时间】:2011-03-09 02:53:32
【问题描述】:

我想在我的应用程序中有一个可展开/可折叠的列表视图,类似于市场中每个应用程序的 cmets 显示方式(实际上,列表中的每个项目都是与市场中相同格式的评论)。由于可能有很多列表项,我不希望用户丢失列表下方的按钮,并且用户可能对阅读列表中的项目不感兴趣,我希望这个列表可以展开和折叠.

我查看了扩展 BaseExpandableListAdapter,它看起来非常简洁,除了似乎总是使用 ExpandableListActivity 显示列表这一事实。我想要嵌入在用户已经在查看的页面中的列表。

有谁知道这是否可以使用 BaseExpandableListAdapter 或者我是否必须完全使用不同的技术并自己编写所有样板代码?

非常感谢, 尼娜

【问题讨论】:

    标签: android android-layout expandablelistview expandablelistadapter


    【解决方案1】:

    是的,使用ListViewExpandableListView 和没有相关活动的朋友并不难。

    您只需要在实例化它或从您的布局中检索它之后在您的ExpandableListView 上调用setAdapter()

    ExpandableListView list = (ExpandableListView) findViewById(R.id.listView);
    list.setAdapter(myExpandableAdapter);
    

    【讨论】:

    • 非常感谢,现在我知道该怎么做了。我没有看到任何关于如何执行此操作的示例,但现在它运行良好。
    【解决方案2】:

    当然。应该没有问题。 ExpandableListActivity 只是ExpandableListView 上的薄薄的一层(实际上,任何具有ExpandableListView 且ID 为android.R.id.list 的布局。您可以将ExpandableListActivity 与您自己的自定义布局一起使用,或者定义您自己的活动并放弃ExpandableListActivity 提供的(相对较少的)便利方法。

    【讨论】:

    • 感谢您的回复,但我需要更具体的内容。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-31
    • 1970-01-01
    • 1970-01-01
    • 2011-10-01
    • 1970-01-01
    相关资源
    最近更新 更多