0

我有一个基于Jeff Sharkey实现的分段列表视图。问题是仅显示列表视图的一部分(最后一个)。以下是我添加这些部分的方法:

SeparatedListAdapter adapter = new SeparatedListAdapter(this);

for (int i = 0; i < groups.size(); ++i)    // groups is an ArrayList<ArrayList<Person>>
{
    ArrayList<Person> group = groups.get(i);
    adapter.addSection("Section test", new MyCustomAdapter(this, R.layout.custom_cell, group));
}

ListView listView = (ListView) findViewById(R.id.myListView);
listView.setAdapter(adapter);
4

1 回答 1

1

试试这个,因为需要第一个参数不同于 addSection 中的前一个参数

for (int i = 0; i < groups.size(); ++i)    // groups is an ArrayList<ArrayList<Person>>
{
    ArrayList<Person> group = groups.get(i);
    adapter.addSection("Section test"+i, new MyCustomAdapter(this, R.layout.custom_cell, group));
}

作为

在代码中添加功能是

public void addSection(String section, Adapter adapter) {
this.headers.add(section);
this.sections.put(section, adapter);
}

其中sections是一个地图

public final Map<String,Adapter> sections = new LinkedHashMap<String,Adapter>();
于 2012-06-25T19:28:56.610 回答