the question is how to pass data from BottomSheetDialogFragment to Fragment or Activity and what would be the correct way ?
Here is my Fragment dialog that will be opened in my Frament and should save data from textview that is getting clicked on.
class BallTypeDialogFragment : BottomSheetDialogFragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?) =
inflater.inflate(R.layout.fragment_blood_type_dialog, container, false)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
text_view_ball_O.setOnClickListener {
text_view_ball_O.text
Toast.makeText(context, "O+", Toast.LENGTH_SHORT).show()
}
text_view_ball_A.setOnClickListener {
text_view_ball_A.text
Toast.makeText(context, "A+", Toast.LENGTH_SHORT).show()
}
text_view_ball_AA.setOnClickListener {
Toast.makeText(context, "AA+", Toast.LENGTH_SHORT).show()
}
text_view_blood_grop_minus.setOnClickListener {
text_view_blood_grop_minus.text
Toast.makeText(context, "-", Toast.LENGTH_SHORT).show()
}
text_view_ball_AAR.setOnClickListener {
text_view_ball_AAR.text
Toast.makeText(context, "R -", Toast.LENGTH_SHORT).show()
}
text_view_ball_AARS.setOnClickListener {
text_view_ball_AARS.text
Toast.makeText(context, "AARS -", Toast.LENGTH_SHORT).show()
}
text_view_ball_OO.setOnClickListener {
text_view_ball_OO.text
Toast.makeText(context, "OO -", Toast.LENGTH_SHORT).show()
}
}
}
And i Simply open it in my Fragment like this,even though I understand it is incorrect.
private fun showDialog() {
val dialog = BallTypeDialogFragment()
dialog.show(childFragmentManager, "BallTypeDialogFragment")
}