i want to make a popup window or alert dialog that appears when ever a specific value is called.
ex: when a value is changed to true a popup window or alert dialog will appear in the screen wherever activity or fragment im at.
the create popup window and alert dialog i use below works but it just depends which activity or fragment its focused and called.
val window = PopupWindow(this@MainActivity)
val view = layoutInflater.inflate(R.layout.called_layout,null)
window.contentView = view
window.showAtLocation(view, Gravity.CENTER, 0, 0)
val builder = AlertDialog.Builder(this)
with(builder)
{
setTitle("sample text")
setMessage("sample text")
setButton("OK", { dialog, which -> dialog.dismiss() })
show()
}
So you need a alert dialog or pop up in any activity then you can create one function and put the dialog code in that function and pass the activity in the parameter.
whenever you need a AlertDialog then just pass that activity name when calling a function and you can access AlertDialog with any activity you want
[Here is the whole code if you want for more specifically understand]
MainActivity - [1]: https://i.sstatic.net/ZTXCo.png Alert function -[2]: https://i.sstatic.net/jrFHF.png
All you need is here for you.