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

前端 未结 1 865
迷失自我
迷失自我 2020-12-12 06:52

I\'m following this tutorial to show cards and integrate Tinder-like swipe feature.

In-between the cards I want to show ads and for that I\'m using

相关标签:
1条回答
  • 2020-12-12 07:40

    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;
    }
    
    0 讨论(0)
提交回复
热议问题