Created
July 8, 2022 14:46
-
-
Save s3va/62c3f83a5310b115780a0996a0a8fb17 to your computer and use it in GitHub Desktop.
Custom Dialog with vidgets pointers to change them programmatically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustDialogFragment(contentLayoutId: Int) : DialogFragment(contentLayoutId) { | |
lateinit var tv: TextView | |
lateinit var pb: ProgressBar | |
/** | |
* Override to build your own custom Dialog container. This is typically | |
* used to show an AlertDialog instead of a generic Dialog; when doing so, | |
* [.onCreateView] does not need | |
* to be implemented since the AlertDialog takes care of its own content. | |
* | |
* | |
* This method will be called after [.onCreate] and | |
* immediately before [.onCreateView]. The | |
* default implementation simply instantiates and returns a [Dialog] | |
* class. | |
* | |
* | |
* *Note: DialogFragment own the [ Dialog.setOnCancelListener][Dialog.setOnCancelListener] and [ Dialog.setOnDismissListener][Dialog.setOnDismissListener] callbacks. You must not set them yourself.* | |
* To find out about these events, override [.onCancel] | |
* and [.onDismiss]. | |
* | |
* @param savedInstanceState The last saved instance state of the Fragment, | |
* or null if this is a freshly created Fragment. | |
* | |
* @return Return a new Dialog instance to be displayed by the Fragment. | |
*/ | |
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | |
// return super.onCreateDialog(savedInstanceState) | |
val builder: AlertDialog.Builder | |
if (activity != null) { | |
builder = AlertDialog.Builder(requireActivity()) | |
} else { | |
throw IllegalStateException("Activity cannot be null") | |
} | |
val inflater = requireActivity().layoutInflater | |
val rootView = inflater.inflate(R.layout.cdlayout, null) | |
tv = rootView.findViewById(R.id.textViewInDiFr) | |
pb = rootView.findViewById(R.id.progressBar2) | |
builder | |
.setView(rootView) | |
//.setView(inflater.inflate(R.layout.cdlayout, null)) | |
//.setView(R.layout.cdlayout) | |
// Add action buttons | |
.setPositiveButton( | |
R.string.positive | |
) { _, _ -> | |
Log.e(TAG, "onCreateDialog: Positive clicked!!!!!!!!!!!!!!!!") | |
activity?.let { fragmentActivity -> | |
Toast.makeText( | |
fragmentActivity, | |
"Positive Button Clicked", | |
Toast.LENGTH_LONG | |
).show() | |
} | |
} | |
.setNegativeButton( | |
R.string.negative | |
) { _, _ -> | |
Log.e(TAG, "onCreateDialog: Negative clicked!!!!!!!!!!!!!!!!") | |
activity?.let { fragmentActivity -> | |
Toast.makeText( | |
fragmentActivity, | |
"Negative Button Clicked", | |
Toast.LENGTH_LONG | |
).show() | |
} | |
} | |
return builder.create() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment