How to control Focus in Recylerview Android

I am using view Pager to implement the page switching effect between the two views. Both views has same layout. In each view I am using horizontal Recycler view. enter image description here

I want that when I am moving from Page A to page B, if my focus is at 2 then after page switch it should go to 4 and if it is on view 1 then to 3. Is there any way to do this.

class AbcAdapter(private val itemListener: ListItemListener) :
RecyclerView.Adapter<AbcAdapter.ViewHolder>() {

private var items = arrayListOf<ListItemData>()
private var dataError = false

private var focusedItem = -1

override fun getItemCount() = items.size

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
    (holder.itemView as TimerListItemView).listItemListener = itemListener
    holder.itemView.update(items[position], dataError)

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
    return ViewHolder(ListItemView(parent.context))

override fun onViewAttachedToWindow(holder: ViewHolder) {
    if (holder.layoutPosition == focusedItem) {

fun setData(newItems: List<ListItemData>) {

fun setDataError(b: Boolean) {
    dataError = b

 * View holder class with one holder for itemView itself.
inner class ViewHolder(itemView: TimerListItemView) : RecyclerView.ViewHolder(itemView) {

    private val viewClock: View? = itemView.findViewById(

    init {
        viewClock?.setOnFocusChangeListener { _, _ ->
            focusedItem = layoutPosition

    fun setFocusOnClockView() {
        if (viewClock?.hasFocus() == false)


This is my adapter class where I am setting the focus.