如何在RecyclerView中添加Admob标语广告

时间:2019-09-15 09:52:43

标签: android-recyclerview admob firebaseui banner-ads

在我的应用中,我正在使用Firebase ui数据库并通过recyclerview显示数据库数据。我在我的recyclerview中添加横幅广告,但我希望以后每3或4个项目展示一次此广告。

MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    doRecyclerView = findViewById(R.id.do_you_recyclerview);
    doLayoutManager = new LinearLayoutManager(this);
    doRecyclerView.setLayoutManager(doLayoutManager);
    dDatabase = FirebaseDatabase.getInstance();
    dReference = dDatabase.getReference("Do_you_know");

    loadDoYouKnow();




}



private void loadDoYouKnow() {

    doAdapter = new FirebaseRecyclerAdapter<DoYou, DouHolder>(
            DoYou.class,
            R.layout.do_you_know,
            DouHolder.class,
            dReference
    ) {
        @Override
        protected void populateViewHolder(DouHolder douHolder, DoYou doYou, int i) {
            douHolder.do_title.setText(doYou.getDo_question());
            douHolder.do_details.setText(doYou.getDo_answer());
        }
    };

    doAdapter.notifyDataSetChanged();
    doRecyclerView.setAdapter(doAdapter);
}

Adapter.java

public TextView do_title;
public TextView do_details;

public DouHolder(@NonNull View itemView) {
    super(itemView);

    do_title = itemView.findViewById(R.id.do_question);
    do_details = itemView.findViewById(R.id.do_answer);
}

如何在我的recyclerview中添加横幅广告?

0 个答案:

没有答案