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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:42:47+00:00 2026-05-26T23:42:47+00:00

I am building an alert box which has a char array of elements which

  • 0

I am building an alert box which has a char array of elements which is used as data for multiple selection checkbox. My question is how to make this alert box return the value as 1,2,3 depending on the selected item order? ie. if i select mercur and venus i have to get the value as 1,2. How will i implement this? As you can see after my try with the for loop it is just now printing which checkbox is checked. Please help me out!!!

  public class MultiActivity extends Activity {
  protected CharSequence[] _options = { "Mercury", "Venus", "Earth", "Mars",  
  "Jupiter", "Saturn", "Uranus", "Neptune" };
  protected boolean[] _selections =  new boolean[ _options.length ];

protected Button _optionsButton;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    _optionsButton = ( Button ) findViewById( R.id.button1);
    _optionsButton.setOnClickListener( new ButtonClickHandler()  );
}


public class ButtonClickHandler implements View.OnClickListener {
    public void onClick( View view ) {
        showDialog( 0 );
    }
}

@Override
protected Dialog onCreateDialog( int id ) 
{
    return 
    new AlertDialog.Builder( this )
        .setTitle( "Planets" )
        .setMultiChoiceItems( _options, _selections, new DialogSelectionClickHandler() )
        .setPositiveButton( "OK", new DialogButtonClickHandler() )
        .create();
}

public class DialogSelectionClickHandler implements DialogInterface.OnMultiChoiceClickListener
{
    public void onClick( DialogInterface dialog, int clicked, boolean selected )
    {
        Log.i( "ME", _options[ clicked ] + " selected: " + selected );
    }
}
public class DialogButtonClickHandler implements DialogInterface.OnClickListener
{
    public void onClick( DialogInterface dialog, int clicked )
    {
        switch( clicked )
        {
            case DialogInterface.BUTTON_POSITIVE:
                printSelectedPlanets();
                break;
        }
    }
}

protected void printSelectedPlanets(){
    for( int i = 0; i < _options.length; i++ ){
        Log.i( "ME", _options[ i ] + " selected: " + _selections[i] );
        String abc = _options[ i ] + " selected: " + _selections[i];
        TextView ab = (TextView)findViewById(R.id.textView1);
        ab.setText(abc);
        System.out.print(abc);

    }
}

}

See i got the below error printed in my logcat when i tried to run the below mentioned code.

11-21 14:23:59.905: E/AndroidRuntime(439): FATAL EXCEPTION: main
11-21 14:23:59.905: E/AndroidRuntime(439): java.lang.NullPointerException
11-21 14:23:59.905: E/AndroidRuntime(439): at com.workspace.multi.peek$2.onClick(peek.java:47)
11-21 14:23:59.905: E/AndroidRuntime(439): at com.android.internal.app.AlertController$AlertParams$4.onItemClick(AlertController.java:886)
11-21 14:23:59.905: E/AndroidRuntime(439): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
11-21 14:23:59.905: E/AndroidRuntime(439): at android.widget.ListView.performItemClick(ListView.java:3382)
11-21 14:23:59.905: E/AndroidRuntime(439): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1696)
11-21 14:23:59.905: E/AndroidRuntime(439): at android.os.Handler.handleCallback(Handler.java:587)
11-21 14:23:59.905: E/AndroidRuntime(439): at android.os.Handler.dispatchMessage(Handler.java:92)
11-21 14:23:59.905: E/AndroidRuntime(439): at android.os.Looper.loop(Looper.java:123)
11-21 14:23:59.905: E/AndroidRuntime(439): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-21 14:23:59.905: E/AndroidRuntime(439): at java.lang.reflect.Method.invokeNative(Native Method)
11-21 14:23:59.905: E/AndroidRuntime(439): at java.lang.reflect.Method.invoke(Method.java:521)
11-21 14:23:59.905: E/AndroidRuntime(439): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-21 14:23:59.905: E/AndroidRuntime(439): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-21 14:23:59.905: E/AndroidRuntime(439): at dalvik.system.NativeStart.main(Native Method)
11-21 14:33:05.145: D/AndroidRuntime(495): Shutting down VM
11-21 14:33:05.145: W/dalvikvm(495): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
11-21 14:33:05.166: E/AndroidRuntime(495): FATAL EXCEPTION: main
11-21 14:33:05.166: E/AndroidRuntime(495): java.lang.NullPointerException
11-21 14:33:05.166: E/AndroidRuntime(495): at com.workspace.multi.MultiActivity$1.onClick(MultiActivity.java:51)
11-21 14:33:05.166: E/AndroidRuntime(495): at com.android.internal.app.AlertController$AlertParams$4.onItemClick(AlertController.java:886)
11-21 14:33:05.166: E/AndroidRuntime(495): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
11-21 14:33:05.166: E/AndroidRuntime(495): at android.widget.ListView.performItemClick(ListView.java:3382)
11-21 14:33:05.166: E/AndroidRuntime(495): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1696)
11-21 14:33:05.166: E/AndroidRuntime(495): at android.os.Handler.handleCallback(Handler.java:587)
11-21 14:33:05.166: E/AndroidRuntime(495): at android.os.Handler.dispatchMessage(Handler.java:92)
11-21 14:33:05.166: E/AndroidRuntime(495): at android.os.Looper.loop(Looper.java:123)
11-21 14:33:05.166: E/AndroidRuntime(495): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-21 14:33:05.166: E/AndroidRuntime(495): at java.lang.reflect.Method.invokeNative(Native Method)
11-21 14:33:05.166: E/AndroidRuntime(495): at java.lang.reflect.Method.invoke(Method.java:521)
11-21 14:33:05.166: E/AndroidRuntime(495): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-21 14:33:05.166: E/AndroidRuntime(495): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-21 14:33:05.166: E/AndroidRuntime(495): at dalvik.system.NativeStart.main(Native Method)

  • 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-26T23:42:47+00:00Added an answer on May 26, 2026 at 11:42 pm

    Check this…

     ArrayList<Integer> pos=new ArrayList<Integer>();
    final CharSequence str[]={"Android","Black Berry","Iphone"};
        private void MultipleChoiceSpinner() {
            // TODO Auto-generated method stub
    
    
            AlertDialog.Builder builder=new AlertDialog.Builder(TestGalleryActivity.this).setMultiChoiceItems(str, default_selected, new  DialogInterface.OnMultiChoiceClickListener()
            {
    
                @Override
                public void onClick(DialogInterface dialog, int which, boolean isChecked) 
                {
                if(isChecked)
                {
                    pos.add(which);
                    default_selected[which]=true;
                }
                    else{
                        pos.remove(pos.indexOf(which));
                        default_selected[which]=false;
                    }
    
    
                }
            }).setTitle("Select Any");
            builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
    
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Toast.makeText(TestGalleryActivity.this, "Selected positions:"+pos.toString(), Toast.LENGTH_SHORT).show();
                }
            });
            d=builder.create();
            d.show();
    
        }
    

    Hi, I am just add two types of alert boxes here. I hope that it will be useful to someone.

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

Sidebar

Related Questions

Building on what has been written in SO question Best Singleton Implementation In Java
I'm building a RESTful web api with asp.net mvc, which returns pure json data.
We are building an email alert system which needs to send customized emails in
building on my last question jQuery getting values from multiple selects together I have
Building a website that has English & Japanese speaking users, with the Japanese users
I am building a page which allows our members to select their notification preferences
I am building a dynamic dropdown navigation. In the dropdown there are multiple floating
I'm building a site which allows users to log on to it, and uses
I'm building a javascript object which mainly should send an authentication ajax request before
To demonstrate XSS attack, I am building a web app which does the following:

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.