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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:13:50+00:00 2026-06-07T14:13:50+00:00

I’m trying to build a multichoice AlertDialog using dynamic data. Ok, it’s all loading

  • 0

I’m trying to build a multichoice AlertDialog using dynamic data.

Ok, it’s all loading great and etc, but the selections are messed up.

Here is my code:

new AlertDialog.Builder(this)
        .setTitle("Cities")
        .setMultiChoiceItems(_options, _selections, new DialogInterface.OnMultiChoiceClickListener(){

                @Override
                public void onClick(DialogInterface dialog, int clicked, boolean selected) {
                        Log.i("Database", _options[clicked] + " selected: " + selected);
                }

        })
        .setPositiveButton("OK", new DialogInterface.OnClickListener(){

                @Override
                public void onClick(DialogInterface dialog, int clicked) {
                    switch(clicked) {
                        case DialogInterface.BUTTON_POSITIVE:
                            for( int i = 0; i < _options.length; i++ ){
                                Log.i("Database", "id: " + _values[i] + " " + _options[i] + " selected: " + _selections[i]);
                            }
                            break;
                    }
                }
        })
        .create();

As you can see in the LogCat, I described my problem:

** OPENED ALERTDIALOG VIA A BUTTON AND SELECTED THE FOLLOWING: **
07-12 16:06:51.347: I/Database(8034): Aveiro selected: true
07-12 16:06:53.936: I/Database(8034): Coimbra selected: true
07-12 16:07:00.116: I/Database(8034): Porto selected: true

** AFTER PRESSING THE OK BUTTON, THIS SHOWS UP, WHICH IS CORRECT: **
07-12 16:07:02.826: I/Database(8034): id: 1 Aveiro selected: true
07-12 16:07:02.826: I/Database(8034): id: 2 Coimbra selected: true
07-12 16:07:02.826: I/Database(8034): id: 3 Porto selected: true
07-12 16:07:02.826: I/Database(8034): id: 4 Minho selected: false

** I CLICKED THE BUTTON TO START THE DIALOG AGAIN DE UNSELECTED THE FOLLOWING: **
07-12 16:07:07.087: I/Database(8034): Coimbra selected: false

** AFTER PRESSING THE OK BUTTON, ALL SHOWS AS FALSE. 1 AND 3 SHOULD BE TRUE: **
07-12 16:07:08.097: I/Database(8034): id: 1 Aveiro selected: false
07-12 16:07:08.097: I/Database(8034): id: 2 Coimbra selected: false
07-12 16:07:08.097: I/Database(8034): id: 3 Porto selected: false
07-12 16:07:08.097: I/Database(8034): id: 4 Minho selected: false
  • 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-07T14:13:52+00:00Added an answer on June 7, 2026 at 2:13 pm

    EDIT

    Tried your code and it is working fine for me. Step through it and make sure your values are correct.

    Here is my test app. The only difference is that i did not know what _values was, so i took it out.

    public class SandBoxActivity extends Activity {
    
        private Button testButton;
    
        private CharSequence[] _options = {"Aveiro", "Coimbra", "Porto", "Minho"};
    
        private boolean[] _selections = {true, true, true, false};
    
        private AlertDialog test;
    
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            test = new AlertDialog.Builder(this)
            .setTitle("Cities")
            .setMultiChoiceItems(_options, _selections, new DialogInterface.OnMultiChoiceClickListener(){
    
                    @Override
                    public void onClick(DialogInterface dialog, int clicked, boolean selected) {
                            Log.i("Database", _options[clicked] + " selected: " + selected);
                    }
    
            })
            .setPositiveButton("OK", new DialogInterface.OnClickListener(){
    
                    @Override
                    public void onClick(DialogInterface dialog, int clicked) {
                        switch(clicked) {
                            case DialogInterface.BUTTON_POSITIVE:
                                for( int i = 0; i < _options.length; i++ ){
                                    Log.i("Database", "id: " + " " + _options[i] + " selected: " + _selections[i]);
                                }
                                break;
                        }
                    }
            })
            .create();
    
            this.testButton = (Button) findViewById(R.id.color_button);
            this.testButton.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    test.show();
                }
            });
        }
    }
    

    OLD POST

    .setMultiChoiceItems(_options, _selections, new DialogInterface.OnMultiChoiceClickListener(){
    
                    @Override
                    public void onClick(DialogInterface dialog, int clicked, boolean selected) {
                            Log.i("Database", _options[clicked] + " selected: " + selected);
                    }
    
            })
    

    I do not see that you are actually handling the fact that it was clicked. I see that you are printing to the log that it was clicked, but you are not changing the fact that it is selected in your _selections array. That could possibly be your problem.

    Try this:

    .setMultiChoiceItems(_options, _selections, new DialogInterface.OnMultiChoiceClickListener(){
    
                    @Override
                    public void onClick(DialogInterface dialog, int clicked, boolean selected) {
                            _selections[clicked] = selected;
                            Log.i("Database", _options[clicked] + " selected: " + selected);
                    }
    
            })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
We're building an app, our first using Rails 3, and we're having to build
I want to construct a data frame in an Rcpp function, but when I
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small

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.