gpt4 book ai didi

android - Jeff Sharkey 的 SeparatedListAdapter 错误

转载 作者:行者123 更新时间:2023-11-29 22:25:44 25 4
gpt4 key购买 nike

我正在使用 Jeff Sharkey's SeparatedListAdapter添加 header 。
起初,一切都很好。
但是,当我添加完全相同的 header 字符串时,问题就出现了。
header 显示不正确,但缺少一些 header 。
当我更改 header 的相同字符串时,这个问题就解决了。
但是,如果我需要使用相同的字符串 header 怎么办?
我想问题的发生是因为...

public final ArrayAdapter<String> headers;

谢谢。


我发现它发生是因为...

public final Map<String, Adapter> sections = new LinkedHashMap<String, Adapter>();

因为是Map,所以重复的String key会导致问题。
map 不知道我需要哪个。

那么,有人知道另一个允许我使用重复字符串键的 SeparatedListAdapter 吗?或者我该如何解决?

谢谢

最佳答案

我只是通过向 SeparatedListAdapter 类添加和使用以下方法来修复它。

 /**
* If you need to show the duplicate header name, use this method to add
* section, be sure that the id must be different.
* CHT 2011/05/14
* @param id
* must differ from each other or problems will happen
* @param section
* header name
* @param adapter
*/
public void addSection(String id, String section, Adapter adapter) {
this.headers.add(section);
this.sections.put(id, adapter);

// Register an observer so we can call notifyDataSetChanged() when our
// children adapters are modified, otherwise no change will be visible.
adapter.registerDataSetObserver(mDataSetObserver);
}

关于android - Jeff Sharkey 的 SeparatedListAdapter 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5996730/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com