开发者

Alertdialog with integrated buttons in the message

开发者 https://www.devze.com 2023-04-07 09:51 出处:网络
I want to do something like Terms of Service in an AlertDialog (it must pop up) where the user has to scroll to the bottom to see the \"accept\" or possible an accompanying decline button. Is there a

I want to do something like Terms of Service in an AlertDialog (it must pop up) where the user has to scroll to the bottom to see the "accept" or possible an accompanying decline button. Is there a way to include buttons in the AlertDialogs MESSAGE that the us开发者_StackOverflow中文版er must scroll through?

Similarly another implementation would just be to have the button unpressable until the user scrolls to the bottom, how would I do that?

Insight appreciated!


I suppose you could always create a custom Dialog and show that. There's a guide on how to do that on the Android developer site right here: http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog

An alternative would be to create a regular class with its own layout and then set the theme to the dialog theme. This will look like a dialog when opening, and allows for pretty much the same functionality as any other Activity.


I believe what you can do is, compare the bottom position of the last item in the dialog, which would be the textview, to the bottom of the scrollview in the onScrollChanged listener. This way, when the user has reached the bottom, you can call

 AlertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true);


Here you go:

AlertDialog.Builder dBuilder = new AlertDialog.Builder(this);
dBuilder.setMessage(msg)
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
        dialog.dismiss();
    }
    })
.setPositiveButton("Accept", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
    /// YOUR OK PART
});
AlertDialog alert = dBuilder.create();
alert.show();

Obviously msg contains your... message :)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号