If you want to show FragmentA
as dialog on background operation response change fragments supper class to FragmentDialog
. This works only if you use Fragment not Activity. And show it by this code:
fun showResponse(fragmentManager:FragmentManager) {
val responseFragment = FragmentA()//or name of your Fragment
responseFragment.show(fragmentManager, "")
}
If you want to show dialog from activity or do not show FragmentA
, create class ResponseDialog
with super class DialogFragment
. In this class in method onCreateDialog
you can design your dialog (add text, buttons, images...).
class ResponseDialog: DialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle): Dialog {
return activity?.let {
val builder = AlertDialog.Builder(it)
builder.setMessage("data downloaded")
.setPositiveButton("Ok",
DialogInterface.OnClickListener { dialog, id ->
//positive button action here dissmis dialog
})
builder.create()
} ?: throw IllegalStateException("Activity cannot be null")
}
}
And show it by this method:
fun showResponse(fragmentManager:FragmentManager) {
val responseFragment = ResponseDialog()
responseFragment.show(fragmentManager, "")
}
Android dialogs documentation