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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:34:22+00:00 2026-06-06T16:34:22+00:00

I am presenting user with a alert dialog which contains 2 items, I want

  • 0

I am presenting user with a alert dialog which contains 2 items, I want to implement an OnClickListener for both items. I am able to set 1 item but when I try to use switch statement, I get this error :

Cannot switch on a value of type CharSequence[]. Only convertible int values or enum constants are permitted

public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

    // TODO Auto-generated method stub
    final CharSequence[] items = {"Reviews", "More Info"};
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Please Select an Option");
    builder.setItems(items, new DialogInterface.OnClickListener() {


        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub

       switch (items){

        case 1 :

            //do something

        case 2:

            Intent intent = new Intent (MyActivity.this, WebViewActivity.class);
            MyActivity.this.startActivity(intent);


        }
    });
AlertDialog alert = builder.create();
alert.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-06T16:34:24+00:00Added an answer on June 6, 2026 at 4:34 pm

    Using strings in a switch case for a menu?

    Strings in switch statements were added in Java 7. For an example, take a look here. Since Android development isn’t currently based on Java 7 syntax, you’ll have to go the alternate route. And that means: if-else statements. They aren’t the prettiest, but they’ll get the job done.

    so can try

     public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub
    
               switch (which){
    
                case 0 :
                        String str = items[which];
                    //do something
    
                case 1:
    
                    Intent intent = new Intent (MyActivity.this, WebViewActivity.class);
                    MyActivity.this.startActivity(intent);
    
    
                }
            });
    

    http://www.botskool.com/geeks/how-create-dialog-box-android-part-2

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

Sidebar

Related Questions

I have a list of items, which I will be presenting to the user
I have a EditText which I am presenting as disabled so that user cannot
I'll use the jQuery plugin for presenting the user with a nice interface The
I'm using a pretty standard recipe for presenting ModalViewControllers in my iPhone apps, but
I don't mind presenting the user with permission dialogs... What's involved in opening a
I am presenting a UIActionSheet when a user double taps my cell: Tap Recognition
My python2 script uploads files nicely using this method but python3 is presenting problems
I want to prevent one of my views from exiting when the user presses
I want to hide animation that shows shutter opening while presenting UIImagePickerController to take
my app involves many viewcontrollers, some of which are memory heave-duty ones. The user

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.