0

someclass_adapterEvents_part 有 20 个项目。循环结束后 GlobalData.buffer 得到 40 而 someclass_adapter 得到 40 我真的很困惑!someclass_adapter 和 GlobalData.buffer 在循环之前都是空的。

SomeClass tmp_sc;
for (int i = 0; i < events_part.size(); i++)
{
    tmp_sc = events_part.get(i);
    someclass_adapter.add(tmp_sc);
    GlobalData.buffer.add(tmp_sc);
}

someclass_adaper 是扩展 ArrayAdapter(SomeClass) 的适配器,缓冲区是静态 ArrayList(SomeClass)。它在java中,特别是在android代码中。我使用 Global.buffer 来初始化 someclass_adapter

someclass_adapter = new SomeClassAdapter(this, R.layout.lv_events_item, GlobalData.buffer);
4

1 回答 1

3

Looks like your someclass_adapter is wrapping the buffer instance. So essentially you are adding same elements twice to the same ArrayList. It will be enough to add them to adapter only.

于 2013-09-30T13:04:03.050 回答