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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:07:05+00:00 2026-06-06T01:07:05+00:00

I want to implement setSingleChoiceItems inside a custom Dialog but unable to do it.

  • 0

I want to implement setSingleChoiceItems inside a custom Dialog but unable to do it. I want when I press a button a custom alert box will pop up with setSingleChoiceItems, then it will go to another activity.

Code below:

package com.ssaa;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class VoteActivity extends Activity {
    /** Called when the activity is first created. */

    Button b;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        b=(Button) findViewById(R.id.vote);
        b.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                showDialog(1);
            }
        });
    }


    public void showallDialog()
    {
        final CharSequence[] items = {"Yes", "No", "Can't Say"};
        AlertDialog.Builder builder = new AlertDialog.Builder(this);


        builder.setTitle("AM I AWESOME?");
        builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int item)
            {
                Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
            }
        });
        AlertDialog alert = builder.create();
    }
    @Override
    protected Dialog onCreateDialog(int id) {
        // TODO Auto-generated method stub
        Dialog d =null;
        switch (id) {
        case 1:

            showallDialog();


        default:
            break;
        }
        return d;
    }

  /*  class MyCustomDialogue extends Dialog
    {

        public MyCustomDialogue(Context context) {
            super(context);
            // TODO Auto-generated constructor stub
        }

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);


        }
    }*/

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
        finish();
    }
}

I think I am doing it wrong in showallDialog() method. Please help me to correct it.

  • 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-06T01:07:06+00:00Added an answer on June 6, 2026 at 1:07 am

    You currently are trying to show a null dialog since you never assign the value of “d” in onCreateDialog

    showallDialog should return your dialog that you created.
    ex:

         public AlertDialog showallDialog()
        {
            final CharSequence[] items = {"Yes", "No", "Can't Say"};
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
    
    
            builder.setTitle("AM I AWESOME?");
            builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int item)
                {
                    Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
                    //create your intent here
                    Intent intent = new Intent(getApplicationContext(), YourNextActivity.class);
                    startActivity(intent);
                }
            });
            return builder.create();
        }
    

    Then when you create your dialog in onCreateDialog you assign “d” to your AlertDialog

    case 1:
       d = showallDialog();
       break;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to implement custom JSP list tag, but have problem with accessing properties
I want implement in my software solution an VBA editor but in c# 3.0.
I want to implement an application which will work as a parser. User will
I want implement paging same as safari in iphone.When user touch below button of
I want to implement 3 DIVs inside a container, just like table rows top
I want to implement file upload in RESTful way using openrasta but not able
I want implement forward geocoding in my app. But I am not able to
We want to implement Public Transport Guide for Android. Inputs will be beginning and
I want to implement a Next feature in my app. The button appears on
I want to implement a simple button in PyQt which prints Hello world when

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.