RecyclerView on a dialog box iin Android

 dialog = Dialog(requireActivity())


binding.btnMenu.setOnClickListener {
dialog = Dialog(requireActivity())
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
dialog.setCancelable(true)
val dialogBinding =
MenuDialogLayoutBinding.inflate(LayoutInflater.from(requireContext()))
dialog.setContentView(dialogBinding.root)

dialogBinding.menuRv.layoutManager = GridLayoutManager(requireContext(), 3)
dialogBinding.menuRv.adapter = MenuItemAdapter(requireContext(), menuItems, this)

dialog.show()
}



Dialog box xml:-

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
xmlns:app="http://schemas.android.com/apk/res-auto">

<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/menu_rv"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

Comments

Popular posts from this blog

Delay using coroutine, splash activity delay, kotlin global scope

Raw method for HTTP request containing all basic operations and under the hood methods and Classes: