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 7808665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:11:57+00:00 2026-06-02T03:11:57+00:00

I need help implementing the code to add a negative or positive button to

  • 0

I need help implementing the code to add a negative or positive button to close my alert dialogue (any help would be much appreciated). I think some of my punctuation in the code needs altering as well so any help would be great 🙂

package kevin.erica.box;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.TextView;
import java.util.Random;

public class TheKevinAndEricaBoxActivity extends Activity {
/** Called when the activity is first created. */
private String[] myString;
private String list;
private String[] myString2;
private String list2;
private static final Random rgenerator = new Random();
private static final Random rgenerator2 = new Random();

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Resources res = getResources();

    myString = res.getStringArray(R.array.myArray);

    list = myString[rgenerator.nextInt(myString.length)];

    myString2 = res.getStringArray(R.array.myArray2);

    list2 = myString2[rgenerator.nextInt(myString2.length)];

    ImageButton ib = (ImageButton) findViewById(R.id.imagebutton1);
    ib.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View erica) {
            AlertDialog.Builder b = new AlertDialog.Builder(
                    TheKevinAndEricaBoxActivity.this);
                  b.setMessage(myString[rgenerator.nextInt(myString.length)]);
            b.setTitle(R.string.title1); 
Dialog d = b.create();
            d.show();

        }
    });
}
}
  • 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-02T03:11:59+00:00Added an answer on June 2, 2026 at 3:11 am

    You can use the below code in your app::::

    AlertDialog.Builder b = new AlertDialog.Builder(TheKevinAndEricaBoxActivity.this);
    b.setMessage(myString[rgenerator.nextInt(myString.length)]);
    b.setTitle(R.string.title1); 
    b.setPositiveButton("Button Text", new DialogInterface.OnClickListener(){
    @Override
    public void onClick(DialogInterface dialog, int which){
        //stuff you want the button to do
    }
    });
    b.setNegativeButton("Button Text", new DialogInterface.OnClickListener(){
    @Override
    public void onClick(DialogInterface dialog, int which){
        //stuff you want the button to do
    }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need some help with this problem in implementing with XSLT, I had already implemented
I need help on this following aspx code aspx Code: <asp:Label ID =lblName runat
I would love some help on a particular design. This is the code I
Need help with implementing a pure abstract class via inheritance , using namespace to
I need some help implementing the Radix sort algorthim in JavaScript. I found this
I am trying my hands on implementing a batch process. I need some help/guidance
I need help implementing a slide function to my slideshow, I've got most of
I really need help implementing a continuous tanh-sigmoid activation function in a very basic
I need some help in implementing jQuery. I have a dropdown list with the
I need help figuring out how to succeed in implementing unobtrusive client-side validation of

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.