I have been searching to make the recyclerview
Carousel so that first item populates again when the last item is visible and it keep on showing again and again. Now I know this answer is already answered here, and here but both these answer didnt solve my problem. Although number of items increased but the fragment which are items in recyclerview do not show anything.
I am inflating fragments
as an items for RecyclerView
which is nested in a ViewPager
. The accepted answers hasnt been able to solve my problem.
Code: RecyclerViewAdapterClass
fun initialize(scrollableData: ArrayList<ScrollableData>, activity: AppCompatActivity) {
this.scrollableData = scrollableData
this.activity = activity
}
override fun getItemCount() = scrollableData.size
override fun getItemViewType(position: Int): Int {
return scrollableData[position].index
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseHolder {
when (viewType) {
ScrollableItems.ABC -> {
val view = parent.inflate(R.layout.view_module_abc, false)
return ABCViewHolder(view, abcPresenterImpl, activity)
}
ScrollableItems.DEF -> {
val view = parent.inflate(R.layout.view_module_def, false)
return DEFViewHolder(view, defControlPresenter, activity)
}
else -> {
val view = parent.inflate(R.layout.view_module_ghi, false)
return GHIViewHolder(view, GHIModulePresenter, activity)
}
}
}
override fun onBindViewHolder(holder: BaseHolder, position: Int) {
holder.bindView()
}
and HomeActivity#setupRecyclerView(...)
private fun setupRecyclerView(scrollableDataList: ArrayList<ScrollableData>) {
linearLayoutManager = CustomLinearLayoutManager(applicationContext, LinearLayout.HORIZONTAL, !DeviceConfig.instance!!.isRegularDevice)
recycler_view.layoutManager = linearLayoutManager
recycler_view.adapter = mainScreenAdapter
mainScreenAdapter.initialize(scrollableDataList, this)
recycler_view.setHasFixedSize(true);
GravityPagerSnapHelper(if (DeviceConfig.instance!!.isRegularDevice) Gravity.START else Gravity.END, true, this).attachToRecyclerView(recycler_view)
recyclerViewScrollListener()
}
and CustomLinearLayoutManager
class CustomLinearLayoutManager(context: Context, orientation: Int, reverseLayout: Boolean)
: LinearLayoutManager(context, orientation, reverseLayout) {
var isScrollEnabled = true
override fun canScrollHorizontally(): Boolean {
return isScrollEnabled && super.canScrollHorizontally()
}
override fun canScrollVertically(): Boolean {
return isScrollEnabled && super.canScrollVertically()
}
}
Please help me resolve this.