how to add buttons dynamically in Alert Box in Android

佐手、 提交于 2020-01-14 03:29:07

问题


I am developing android application in which for validations, it displays messages with alert box. I wanted to add buttons dynamically according to certain conditions. I like ask how to do this? I searched on Google, but couldn't find any suitable solutions.

Any Suggestions are helpful. Thanks.


回答1:


You can use a DialogFragment to acheive it. Create your own dialog view and inflate it in the onCreateView() of the dialog fragment.




回答2:


if you know the possible buttons that could be displayed:

  • add them to your layout
  • use the visibility attributes to show or hide it them, according to your conditions. (How To)



回答3:


i got the answer, I used Command Design pattern with help of CommandWrapper.

The following link elaborate more precisely. link

Thank you for everyone for their suggestions.



来源:https://stackoverflow.com/questions/11607236/how-to-add-buttons-dynamically-in-alert-box-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!