Swipe refresh layout not working with recyclerview

when you define swipeRefreshLayout as local into onCreate view it accesses only that block. if defined in the global swipeRefreshLayout it accesses anywhere in the class.

var swipeRefreshLayout: SwipeRefreshLayout? = null

In onCreate method

swipeRefreshLayout = binding.swipeRefreshLayout

For Calling

swipeRefreshLayout?.isRefreshing = false