How to show CardView containing ads randomly but not before 3 cards and not after 7 cards?

非 Y 不嫁゛ 提交于 2019-11-28 14:44:25

If you know the cards to be put from before then what you can do is 1. create a card stack 2. put first two non-add-cards 3. Then make a random test if it has to put a add-card for third else put the non-add-card. 4. do this card put with test till 7 cards.

Example:

boolean atLeastOneAddPut = false;

int count = 1;
for(Data data: DataArray){
    if(count > 2 && count < 8 && shouldPutAdd()){
        mSwipeView.add(new AddView());
        count++;
    }
    mSwipeView.add(new NonAddView(data));
    count++;
}

private boolean shouldPutAdd(){
    //generate random 0 and 1
    int random;
    ...
    return random == 1;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!