android - Jeff Sharkey 的 SeparatedListAdapter 错误

标签 android

我正在使用 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/

相关文章:

android - 如何将 LatLng 实例发送到新 Intent

java - MockWebServer 的 takeRequest() 方法需要很长时间才能响应或挂起

android - 是否可以编辑/修改.SO文件?

android - params.getBehaviour() 返回空值

android - 如何查看 Android 上是否连接了 Wi-Fi?

android - 适配器 Android 中的错误

Galaxy Tab 10.1 上的 Android ADK 错误

android - 什么 Android 布局允许包装 block /按钮 - 而不是奇怪的拉伸(stretch)?

android - 我的按钮中的文字从下方剪切

java - 返回下一个 N 个单词和前一个 N 个单词以显示的有效方法