我使用了名为“IntruderShanky/SectionedRecyclerView”的分段回收视图库。
使用这个库,我已经成功地添加了带有子项目的部分,但问题是我必须在每 10 个项目之后添加广告。
假设我有 5 个部分,每个部分有 10 个孩子,即
void section_item_adder()
{
for (int j=0;j<5; j++) {
for (int i = 0; i < 10; i++) {
childList.add(new Child(Section_filepath, Section_filename, false, FileSize_Check));
}
sectionHeaders.add(new SectionHeader(childList, "Group " + section_counter + "", section_counter + 1));
}
}
对于子项,我将子类对象作为列表传递,但是我应该如何处理要在部分中作为子项传递的原生广告。
public static final int ITEM_PER_AD = 10;
void SetAdsInAdapter()
{
for(int i = 0; i < sectionHeaders.size();i+= ITEM_PER_AD)
{
final AdView adView = new AdView (MainActivity.this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId(NATIVE_AD_ID);
// sectionHeaders.add(new SectionHeader(childList, "" ,section_counter+1));
// adapterRecycler.a
sectionHeaders.add(new SectionHeader(section_counter+1));
}
}