按需显示/隐藏列表视图部分索引

发布于 2024-11-25 23:47:42 字数 342 浏览 5 评论 0原文

我实现了一个列表视图,它实现了SectionIndexer ... 到目前为止一切都很好。

通常,项目按名称排序,但我还提供了以不同方式对列表进行排序的选项 - 按距离(从用户到对象)。

因此,当列表以第二种方式排序时,我想隐藏之前生成的SectionIndex。

我就是做不到。

我尝试过,重写了大部分方法, 我在构造函数中尝试了分离(清楚为什么它不起作用,它不会被第二次调用) 我什至尝试过实现第二个列表适配器,只是使用另一个列表适配器?即使在这种情况下,也会显示 SEctionIndex!我实在是看不懂这个。

如果有人知道发生了什么事,那就太好了:)

非常感谢,迈克

i implemented a listview which implements SectionIndexer ...
everything fine so far.

Normally the items are sorted by Name, but i also offer the option to sort the list in a different way - by distance (from the user to the objects).

So, when the list is sorted the 2nd way, i want to hide the previously generated SectionIndex.

I'm just not able to do so.

I tried, re-writting most of the methods,
I tried it with a separation in the Constructor (clear why it doesnt work, it doesnt get called a second time)
I even tried it with implementing a second listadapter, and just using a different one? Even in this case the SEctionIndex is shown! I really don't understand this one.

So would be really great, if anyone knows whats going on :)

thanks a lot, mike

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

唯憾梦倾城 2024-12-02 23:47:42

你的观察是正确的。让我首先告诉你为什么构造函数永远不会被第二次调用。 SectionIndexer 是一种特殊的类型。他们仅为特定数据集创建一次索引,并在该适配器上重复使用它们。我遇到的更大问题是当适配器的底层数据发生变化时,sectionIndexer 仍然保持不变。

检查我的问题和答案。

回到您的查询。

如果在选择第二个选项后更改方向,您会发现构造函数将被调用,并且您将能够再次重新填充sectionIndex。所以基本上你需要再次调用 onSizeChanged 并重新填充sectionIndex。

Your observations are correct. Let me tell you first why the constructor never gets called the second time. SectionIndexer are a special kind. They create the index only once for a particular set of data and re-use them on that adapter. The bigger issue which I had come across was when the underlying data changed for the adapter, the sectionIndexer still remained the same.

Check my Question and the answer there.

Coming back to your query here.

If you change the orientation after selecting the second option, you would observe that the constructor will get called and you will be able to re-populate the sectionIndex again. So basically you need to call onSizeChanged again and get the sectionIndex repopulated.

浊酒尽余欢 2024-12-02 23:47:42

当您用不同的方式缩短列表时,您有两个选项可以重新加载。

填充适配器的新集合后

1),您可以通知此适配器。

2)您可以再次填充设置适配器。

When you Short your List with different way ,you have a two option to load again .

after filled those new collection for adapter

1) you can make a notify this adapter .

2) you can fill set adapter again .

跨年 2024-12-02 23:47:42

如果通过仍然显示的SectionIndexer,您的意思是部分覆盖,您可以通过调用 setFastScrollEnabled(false)

If by SectionIndexer which remains displayed you mean the section overlay you can achieve this by calling setFastScrollEnabled(false) before to switch to your other listadapter which does not implements SectionIndexer.

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