现象
总是加载数据的总集合大小为0,后来经过断点调试才发现原因:i 和 j 不能混淆
for (int i =0; i < songsTypes.size(); i++)
{SongsType songsType = songsTypes.get(i);int mCurrentId = songsType.getId();
MusicSortItem musicSortItem = new MusicSortItem();musicSortItem.setmTitle(songsType.getType_name());
musicSortItem.setType(true);allItems.add(musicSortItem);
for (int j =0; j < songSheetBeanList.size();j++)
{SongSheetBean ssb = songSheetBeanList.get(j);if (mCurrentId == ssb.getType_id()
{
MusicSortItem musicSortItemSub = new MusicSortItem();
musicSortItemSub.setmTitle(ssb.getSSheet());
musicSortItemSub.setType(false);musicSortItemSub.setShid(ssb.getShid());
allItems.add(musicSortItemSub);
}
}
}
需要注意
嵌套循环外层和层的循环,不能混淆颠倒位置