We need you to edit your item Layout, so it has a wrapper/holder for the Ads. |
// 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 layour is the most common but feel free to swap it rv.layoutManager = LinearLayoutManager(this) |
Normal item code would look something like the following →
<?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 a wrapper to the 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> |
# MainActivity.kt val infiniteScrollConfigId = ConfigBuilder.INFINITE_SCROLL_TEST_R89_CONFIG_ID val itemAdWrapperTag = "infiniteScroll_ad_wrapper_tag" RefineryAdFactory.createInfiniteScroll(infiniteScrollConfigId, rv, itemAdWrapperTag) |
Your They can be many or none depending on your requests, if you need one or more please request them to your account manager or technical account manager. |
When not using a Recyclerview we need to create the infinite scroll manually and use the returned id to show ads in each of the items
val infiniteScrollConfigId = ConfigBuilder.INFINITE_SCROLL_TEST_R89_CONFIG_ID val infiniteScrollId = RefineryAdFactory.createManualInfiniteScroll( infiniteScrollConfigId ) |
Your They can be many or none depending on your requests, if you need one or more please request them to your account manager or technical account manager. |
Normal item code would look something like the following →
<?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 a wrapper to the 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:id="@+id/item_ad_container" 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> |
Then in each item, you will need to get the wrapper and then use it to request the ad as well you will need to tell to the request method what is the “item position number in the scroll”
val itemPosition: Int = getPositionInScrollMethod() val adWrapper = itemView.findViewById<ViewGroup>(R.id.itemAdContainer) RefineryAdFactory.getInfiniteScrollAdForIndex( infiniteScrollId, this.adapterPosition, adWrapper ) |
Careful on the implementation of This needs to be implemented according to your implementation of the infinite scroll. EX: 20 items per page so first 20 items go from 0 to 19 and the first item of the second page is not 0 is 20 formula beeing -> pageItemIndex + (pageSize*currentPage) so first item position of first page is 0 + (20*0) item 0 plus 20 multiplied by the current page index, so page 1 has index 0 and first item position of the second page is 0 + (20*1) item 0 plus 20 multiplied by the current page index, so page 2 has index 1 second item first page would be 1 + (20*0) = 1 second item second page would be 1 + (20*1) = 21 and so on |
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.INFINITE_SCROLL_TEST_R89_CONFIG_ID val infiniteScrollLifecycleListener = <create the listener with a method or inplace> RefineryAdFactory.createInfiniteScroll(infiniteScrollConfigId, rv, infiniteScrollLifecycleListener) |