How to add a check box to an alert dialog

后端 未结 4 1108
臣服心动
臣服心动 2020-12-13 12:10

Currently when the user opens my app, an AlertDialog opens, asking them if they would like to upgrade to the pro version.

I need to add a CheckBox

4条回答
  •  伪装坚强ぢ
    2020-12-13 12:57

    First you need to define a layout that contains the message and checkbox for disabling the alert on subsequent views. Then instead of calling builder.setMessage, you'll call:

    builder.setView(myAlertViewWithDisablingCheckbox);
    

    Then when the user clicks on the alert dialog button, you'll have to check to see if that checkbox has been checked, and save that preference in your app's SharedPreferences. Then you can use that preference to determine if this alert dialog should be shown to the user again.

提交回复
热议问题