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

  • Home
  • SEARCH
  • 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 996861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:56:38+00:00 2026-05-16T06:56:38+00:00

I’ve been trying to get a handle on Dialogs. I read the android dev

  • 0

I’ve been trying to get a handle on Dialogs. I read the android dev site info and a dozen bolg’s. It seems there are several ways of doing it and I’m able to at least get a dialog with 3 buttons (not using a custom dialog with custom layout).

If I set up the positive/negative/neutral actions with something like finish(), cancel() etc, it works with those calls.

But, what I want to do is have the buttons do something more, if only display a text using a string defined in the Maincode (not a Toast). Eventually, I want to enter some numbers in a dialog and return them in a string. Yes, I can do that from another activity screen but, prefer not to as I like the compact size of a dialog.

Even cheating and returning an integer to the Maincode to do some switch/case stuff would be okay but, I seem not able to even return an integer.

I understand that I’ll need to do a customized alert dialog to do input stuff and the following is my attempt at a start by just trying to return a string or integer – it doesn’t seem to be getting me there!

This code presents the dialog with 3 buttons. This is just one of the try’s I made (integer return stuff deleted)…

What can I do to return an integer to the Maincode from a dialog button? There are no code errors or warnings, it just doesn’t work as I hoped…

    public class Maincode extends Activity {
public static String rtndMessage = "Push Button";
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    final TextView text = (TextView) findViewById(
            R.id.TextView01);
    final Button doIt = (Button) findViewById(R.id.Button01);

    //  -----------------------------------------------------
    doIt.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // do something
            Dialog1();          // call Dialog1
        }
    }); // end -----------------------------------------------
// do the rest of the code (ie, display the result of doIt)
text.setText(rtndMessage);  // set text w/result
}//end onCreate ----------------------------------------------

public void Dialog1() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Dialog Test");
builder.setIcon(R.drawable.redtest);
// chain the following together
  builder.setMessage("Send text: Yes, No, Cancel")
    // the positive action ----------------------------------
    .setPositiveButton("Yes Action", new
        DialogInterface.OnClickListener(){
        public void onClick(DialogInterface dialog, int id){            
            Maincode.rtndMessage = "sent Yes back";             
        }
    })
    // The negative action ----------------------------------
    .setNegativeButton("No Action", new
            DialogInterface.OnClickListener(){
        public void onClick(DialogInterface dialog, int id){
            Maincode.rtndMessage = "sent No back";
        }
    })
    // The negative action ------------------------------
    .setNeutralButton("Cancel", new
            DialogInterface.OnClickListener(){
        public void onClick(DialogInterface dialog, int id){
            Maincode.rtndMessage = "sent N/A back";
            dialog.cancel();    // just return to activity
        }           
});    

builder.show(); // show the dialog
}//end Dialog
}//end 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-05-16T06:56:39+00:00Added an answer on May 16, 2026 at 6:56 am

    You can implement the dialog as separate Activity and get any behavior you need. Just apply standard android Theme.Dialog theme to the activity to make it look like dialog. Also you can create theme of your own pointing Theme.Dialog as parent.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.