简体   繁体   English

如何在Android中创建子AlertDialog /对话框?

[英]How to create sub AlertDialog/Dialog box in Android?

I need to develop a menu in Android, so for that I am using AlertDialog. 我需要在Android中开发一个菜单,因此我正在使用AlertDialog。 But the problem that I am getting is that , how do I develop menu with sub AlertDialog/Dialog. 但是我得到的问题是,如何用子AlertDialog / Dialog开发菜单。 I hope the picture will make everything clear. 我希望图片能使一切清晰。 And in the same time the Dialog should have back button so that if a user desires he would be able to move to the first menu. 同时,对话框应具有“后退”按钮,这样,如果用户愿意,他将能够移至第一个菜单。 Thanks 谢谢

用AlertDialog / Dialog模拟子菜单

How about this - when you create AlertDialog 2, pass in the context of AlertDialog 1, using dialog.getContext() (instead of, say, passing in the original Activity ).. and so on? 怎么样-当您创建AlertDialog 2时,使用dialog.getContext()传递AlertDialog 1的上下文(而不是传递原始的Activity )。等等? I believe that would make AlertDialog 2 "appear over" AlertDialog 1. Cancelling dialog 2 or pressing back button should take you back to dialog 1. 我相信这会使AlertDialog 2“出现”在AlertDialog 1上。取消对话框2或按返回按钮应该使您返回到对话框1。

You could extend the same notion to dialog 3 (ie, pass in the context of dialog 2 while creating dialog 3) .. and so on. 您可以将相同的概念扩展到对话框3(即,在创建对话框3时传入对话框2的上下文)等等。

why dialogs? 为什么要对话?

i think, it is possible to call multiple dialogs. 我认为,可以调用多个对话框。

but i would suggest (though unconventional) you can have PreferenceActivity which can nest menus. 但我建议(尽管是非常规的)您可以拥有可以嵌套菜单的PreferenceActivity remember setting pages. 记住设置页面。

and for blocking the main UI (if you want) you can invoke the activity with a dialog theme . 为了阻止主用户界面(如果需要),您可以使用对话框主题调用活动。

this will be easier to code and maintain. 这将更易于编码和维护。 and you can have your back button as well. 您也可以使用后退按钮。

you can call activity for result and get the result in the main activity. 您可以为结果调用活动,并在主活动中获取结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM