2012-06-25 70 views
0

我有一个基于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); 
+0

有多少部分(在实际数据中)? –

+0

Dheeresh,++ i和i ++在这里有相同的效果。我记录了数组的大小,并且他们有正确的数据。 8节,每节2-5行。 – jmosesman

+0

感谢您提供的信息........... :) –

回答

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

其中部分是地图

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

Doh!你是对的。我没有把章节标题想成章节键,所以每次都会覆盖它。谢谢! – jmosesman

+0

永远欢迎.... :) –