Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8874827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:49:13+00:00 2026-06-14T18:49:13+00:00

i try to make own confirm dialog class with boolean value as result. i

  • 0

i try to make own confirm dialog class with boolean value as result. i have read any tutorial or suggestion but the results are not as I want.

The problem is I hate to write long coding, I wanted to write a simple coding. This comparison delphi to android in writing confirmation dialog

Delphi:

if MessageDlg ('Message Text', mtConfirmation, [mbYes, mbNo], 0)

Android:

boolean answer = false;

public boolean Confirm (Activity act, String Title, String ConfirmText,
CancelBtn String, String OkBtn) {
  AlertDialog dialog = new AlertDialog.Builder (act). Create ();
  dialog.setTitle (Title);
  dialog.setMessage (ConfirmText);
  dialog.setCancelable (false);
  dialog.setButton (DialogInterface.BUTTON_POSITIVE, OkBtn,
  new DialogInterface.OnClickListener () {
    public void onClick (DialogInterface dialog, int buttonId) {
  answer = true;
  }
});
dialog.setButton (DialogInterface.BUTTON_NEGATIVE, CancelBtn,
new DialogInterface.OnClickListener () {
  public void onClick (DialogInterface dialog, int buttonId) {
    answer = false;
  }
});
dialog.setIcon (android.R.drawable.ic_dialog_alert);
return answer;
}

the question is can I create a class that generate a confirmation dialogue will produce a Boolean value true or false, just as in Delphi.

confirmation dialog so that the class can be used in class or another activity

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T18:49:14+00:00Added an answer on June 14, 2026 at 6:49 pm

    Android is not always conventional. You can’t show a dialog and wait for it to be displayed, then do something.

    You need to show a dialog, and respond to the yes / no buttons in a callback.

    Something like this is one solution:

    /**
     * Display a confirm dialog. 
     * @param activity
     * @param title
     * @param message
     * @param positiveLabel
     * @param negativeLabel
     * @param onPositiveClick runnable to call (in UI thread) if positive button pressed. Can be null
     * @param onNegativeClick runnable to call (in UI thread) if negative button pressed. Can be null
     */
    public static final void confirm(
            final Activity activity, 
            final int title, 
            final int message,
            final int positiveLabel, 
            final int negativeLabel,
            final Runnable onPositiveClick,
            final Runnable onNegativeClick) {
    
                AlertDialog.Builder dialog = new AlertDialog.Builder(activity);
                dialog.setTitle(title);
                dialog.setMessage(message);
                dialog.setCancelable (false);
                dialog.setPositiveButton(positiveLabel,
                        new DialogInterface.OnClickListener () {
                    public void onClick (DialogInterface dialog, int buttonId) {
                        if (onPositiveClick != null) onPositiveClick.run();
                    }
                });
                dialog.setNegativeButton(negativeLabel,
                        new DialogInterface.OnClickListener () {
                    public void onClick (DialogInterface dialog, int buttonId) {
                        if (onNegativeClick != null) onNegativeClick.run();
                    }
                });
                dialog.setIcon (android.R.drawable.ic_dialog_alert);
                dialog.show();
    
            }
    
    }
    

    To use the above method, something like this can be used:

            Alert.confirm(activity, R.string.titFileExport, R.string.lblFileConfirmOverwrite, 
                    R.string.yes, R.string.no, 
                    new Runnable() { public void run() {performExport(activity, app, currentSong, saveFile);}}, 
                    null);
            return;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to make an animation with an image in my view but it
I have been using the Learning Java 2nd Edtion book to try make my
I have an assignment and I need to make my own (simple) generic linked
New to C, and try to make my own first library. However gcc says
I've been trying to make my own plugin system. I have 2 separate projects.
I would like to make my own ThreadPool type class in Java (I tried
In my ever so harsh endeavor to make my own apps, i have hit
Like always I try to do this for my own, I read the documentation
Hi all I try to make my own tooltip script which follow my mouse
When I make my own Android custom class, I extend its native class. Then

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.