Date Picker Dialog not showing in Fragment
class VerifikasiInfoPribadiFragment : BaseFragment() {
override fun getLayoutResId(): Int = R.layout.fragment_verifikasi_info_pribadi
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
edtTanggalLahir.setOnClickListener {
showDatePicker()
}
}
private fun showDatePicker() {
val calendar = Calendar.getInstance()
val year = calendar.get(Calendar.YEAR)
val month = calendar.get(Calendar.MONTH)
val dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH)
val datePicker = DatePickerDialog(
requireActivity(),
DatePickerDialog.OnDateSetListener { view, year, month, dayOfMonth ->
edtTempatLahir.setText("" + dayOfMonth + "/" + month + "/" + year)
},
year,
month,
dayOfMonth
)
datePicker.show()
}
}
i've try in Activity look good
Maybe it is happening because you called showDatePicker() in onActivityCreated() according to the life cycle, though the activity has created right now, the fragment might not be created yet so try calling the method inside onViewCreated() or onCreateView()