1. Home
  2. Docs
  3. Android – Monetize ...
  4. Use Manual
  5. Ad Formats
  6. Infinite Scroll

Infinite Scroll

Prerequisites

We need you to edit your item Layout, so it has a wrapper/holder for the Ads. Keep in mind this wrapper/holder could be expanded or contracted, so make sure your layout adapts to this changes look into adaptive layouts for this, this size changes in the layout will be limited by the ad configurations that the infinite scroll is using, these can be edited in the code on manual initialization, or in our dashboard in case of auto and single tag initialization.

This is because we can not edit your data for adding new items to the adapter, so we take the existing item views and add the ads to them. You can customize which items have ads when you create the configuration for the infinite scroll.


Get the RecyclerView

      // Find your view, this is the simplest but there are better ways
      val rv = findViewById<RecyclerView>(R.id.infiniteScroll_recyclerView_manual)
      
      // Create and use your own adapter
      rv.adapter = <add your adapter>
      
      // Linear layout is the most common but feel free to swap it
      rv.layoutManager = LinearLayoutManager(this)

Prepare the Item View

Normal item Code would look something like

      <?xml version="1.0" encoding="utf-8"?>
      <androidx.constraintlayout.widget.ConstraintLayout
          xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:app="http://schemas.android.com/apk/res-auto"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_marginStart="10dp"
          android:layout_marginEnd="10dp">
      
          <Button
              android:id="@+id/infinitescroll_item_button_auto"
              android:layout_width="0dp"
              android:layout_height="wrap_content"
              android:text="Button"
              app:layout_constraintBottom_toBottomOf="parent"
              app:layout_constraintEnd_toEndOf="parent"
              app:layout_constraintStart_toStartOf="parent"
              app:layout_constraintTop_toTopOf="parent"
              app:layout_constraintVertical_bias="0.0" />
      
      </androidx.constraintlayout.widget.ConstraintLayout>

For adding the wrapper to this item we would do something like

      <?xml version="1.0" encoding="utf-8"?>
      <androidx.constraintlayout.widget.ConstraintLayout
          xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:app="http://schemas.android.com/apk/res-auto"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_marginStart="10dp"
          android:layout_marginEnd="10dp">
      
          <Button
              android:id="@+id/infinitescroll_item_button_auto"
              android:layout_width="0dp"
              android:layout_height="wrap_content"
              android:text="Button"
              app:layout_constraintBottom_toBottomOf="parent"
              app:layout_constraintEnd_toEndOf="parent"
              app:layout_constraintStart_toStartOf="parent"
              app:layout_constraintTop_toTopOf="parent"
              app:layout_constraintVertical_bias="0.0" />
      
          <FrameLayout
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:tag="infiniteScroll_ad_wrapper_tag"
              app:layout_constraintBottom_toBottomOf="parent"
              app:layout_constraintEnd_toEndOf="parent"
              app:layout_constraintStart_toStartOf="parent"
              app:layout_constraintTop_toBottomOf="@+id/infinitescroll_item_button_auto"
              app:layout_constraintVertical_bias="0.0">
          </FrameLayout>
      
      </androidx.constraintlayout.widget.ConstraintLayout>

Show the Ad

In the example we are using a Test Id.

If you are not testing the app, change it for the proper ID that you got from us.


      # MainActivity.kt
      val infiniteScrollConfigId = ConfigBuilder.INFINITE_SCROLL_TEST_R89_CONFIG_ID
      val itemAdWrapperTag = <Defined ad wrapper tag for each item view that's going to be in the recycler view>
      RefineryAdFactory.createInfiniteScroll(infiniteScrollConfigId, rv, itemAdWrapperTag)

Lifecycle Events

You can subscribe to these events with the same method but passing a new object as a parameter. Details about this object can be found in the Reference.

              # MainActivity.kt
              val infiniteScrollConfigId = ConfigBuilder.BANNER_TEST_R89_CONFIG_ID
              val infiniteScrollLifecycleListener = <create the listener with a method or inline>
              RefineryAdFactory.createInfiniteScroll(infiniteScrollConfigId, rv, infiniteScrollLifecycleListener)

How can we help?