开发者

Jeff Sharkey's SeparatedListAdapter Bugs

开发者 https://www.devze.com 2023-03-05 14:17 出处:网络
I was using Jeff Sharkey\'s SeparatedListAdapter to add headers.开发者_如何学Python At first, everything was all right.

I was using Jeff Sharkey's SeparatedListAdapter to add headers.开发者_如何学Python

At first, everything was all right.

However, when I added the exactly same String of the header, the problem showed up.

The headers didn't show correctly but be lack of some headers.

This problem was solved when I changed the same String of the headers.

But what if I need to use the same String headers?

I guess the problem happened because of...

public final ArrayAdapter<String> headers;

Thanks.


I found that it happened because...

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

Because of Map, so the duplicate String key will cause the problem.

The map doesn't know which one is my need.

So, does anyone know the other SeparatedListAdapter that allows me to use duplicate String key? Or how can I fix it?

Thanks


I just fixed it by adding and using below method to the SeparatedListAdapter class.

 /**
 * 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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消