8

有没有人有任何运气调整PinnedHeaderListView以便它可以与ExpandableListView一起使用,而不仅仅是带有索引部分的简单 ListView?我基本上想要一个ExpandableListView每个组项目视图保持固定在顶部的位置,直到它被下一个组视图向上推。

我研究了代码,试图弄清楚它是如何PinnedHeaderListView工作的,似乎很难适应ExpandableListView. 主要问题似乎在于使用了不同类型的适配器和绘图方法。APinnedHeaderListView利用SectionIndexer来跟踪部分位置。当它绘制每个项目时,getView()它会检查该项目是否是新部分的开始。如果该项目是新部分的开头,则它会使部分标题项目的list_item视图中可见。AnExpandableListAdapter具有 agetChildView()和 agetGroupView()将项目和部分分别绘制为不同的列表项。

我确信一定有某种方法可以使用 in 中的方法PinnedHeaderListView来获得类似的行为ExpandableListView,但我不知道从哪里开始。

4

2 回答 2

4

我能够在ExpandableList1 APIdemo上获得固定的标题。

我面临的最困难的问题是弄清楚如何让 SectionIndexer 与扩展列表很好地配合。正如我的问题所证明的那样,我认为这一切都是错误的。在我最初解决此问题的尝试中,我在 MyExpandableAdapter 中创建了一个 SectionIndexer 对象并将其映射到我的数据,类似于在联系人应用程序和 Peter 的示例中完成的方式。这适用于联系人应用程序,因为平面列表位置静态匹配数据集。在可展开的列表视图中,平面列表位置会随着组的展开和展开而变化。

因此,解决方案不是将部分索引器映射到数据,而是映射到 ExpandableListView 的实例。使用此解决方案,您甚至不需要示例中使用的 SectionIndexer 对象。您只需将 SectionIndexer 实现方法包装在 ExpandableListView 方法周围,如下所示:

    @Override
    public int getPositionForSection(int section) {
        return mView.getFlatListPosition(ExpandableListView
                .getPackedPositionForGroup(section));
    }

    @Override
    public int getSectionForPosition(int position) {
        return ExpandableListView.getPackedPositionGroup(mView
                .getExpandableListPosition(position));
    }

当然,您还必须进行其他更改才能使这一切正常工作,但上述方法是关键。我会尽快将完整代码发布到谷歌代码或 github 并从这里链接。带有固定标题的 ExpandableLists 看起来很棒!

于 2011-06-08T18:26:08.047 回答
1

好吧,我只做了3 个步骤:

1.添加build.gradlecompile 'com.diegocarloslima:fgelv:0.1.+@aar' _

2.在xml中添加ExpandableListView 。

<com.diegocarloslima.fgelv.lib.FloatingGroupExpandableListView
        android:id="@+id/expandableListView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        android:groupIndicator="@null" />

3.Java代码:

FloatingGroupExpandableListView expandableListView = (FloatingGroupExpandableListView) findViewById(R.id.expandableListView);
MyexpandableListAdapter adapter = new MyexpandableListAdapter(context, mList);
WrapperExpandableListAdapter wrapperAdapter = new WrapperExpandableListAdapter(adapter);
expandableListView.setAdapter(wrapperAdapter);

希望这会帮助你。

于 2016-05-17T12:03:05.190 回答