I have a dialog and i have many activities... I need to call the same dailog in all the activities...currently i have written the code in each of the activity but this is not the right way... Can any one help me in this
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
Simply create a class and within that create a static method(say displayDialog), and within this, copy paste the code that displays your dialog. Now call this static method from anywhere in your project. But you might have to pass the context of the calling activity to the static method.
You should regroup the code that builds the
Dialog
in a helper class.Below is an excerpt of a
DialogHelper
I have built for myself and that I use to show my applications' help files.This way I just call
from all my applications. That's a lot of parameters but this is workable.
There is a non-nice thing in that code: I use
setNegativeButton()
for something else than its intended purpose. This is something I should refactor, but this doesn't change anything in the approach.About the parameters of
showHelp()
: they arefinal
as they are used in the anonymous classes built within the method. This is a requirement of the compiler.Ok below is my way of implementing dialog its in a static class so I can call it from any activity when I need