【问题标题】:Sectioned list view only showing last section分段列表视图仅显示最后一个部分
【发布时间】:2012-06-25 18:49:31
【问题描述】:

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

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);

【问题讨论】:

  • 有多少个部分(在真实数据中)?
  • Dheeresh, ++i 和 i++ 在这里具有相同的效果。我已经记录了数组的size,它们有正确的数据。 8 节,每节 2-5 行。
  • 感谢您提供信息............)
  • 如果您需要,这里有更多信息:stackoverflow.com/questions/24853/…
  • " 8 个部分,每个部分 2-5 行。"我正在考虑这个信息..

标签: android listview android-widget


【解决方案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>();

【讨论】:

  • 噢!你说的对。我没有将节标题视为节键,因此每次都将其覆盖。谢谢!
猜你喜欢
  • 2013-07-27
  • 1970-01-01
  • 1970-01-01
  • 2016-05-19
  • 1970-01-01
  • 2016-03-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多