How do I print Yes and No in the dialog box on Android?

Asked 1 years ago, Updated 1 years ago, 101 views

AlertDialog when making a dialog.I know you're using Builder, but I think it's better to use a dialog on Android It's too hard.

if (MessageBox.Show("Sure?", "", MessageBoxButtons.YesNo) == DialogResult.Yes){
    //Do something...
}

When I developed it on a dot-net, I did it like this, but I wonder how Android does this kind of thing.

android alertdialog

2022-09-22 16:57

1 Answers

AlertDialog.Builder is not difficult to use. It might seem a little difficult at first, but after a few tries, it's going to be an easy, very powerful tool. I'll give you a simple example because you seem to want to know how to use it.

DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
        switch (which){
        case DialogInterface.BUTTON_POSITIVE:
            //Process when clicking the Yes button 
            break;

        case DialogInterface.BUTTON_NEGATIVE:
            //Process when clicking the No button 
            break;
        }
    }
};

AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage("Are you sure?").setPositiveButton("Yes", dialogClickListener)
    .setNegativeButton("No", dialogClickListener).show();


2022-09-22 16:57

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.