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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:07:40+00:00 2026-05-31T23:07:40+00:00

Ok here I have a switch case statement which is falling through and trying

  • 0

Ok here I have a switch case statement which is falling through and trying every option. Basically I want something that if the user enters the letter A in the textbox the background will change to b! if they dont enter the letter A then I want it to stop executing the code. But what has been happening is if the user enters lets say for example the letter Q when the background is letter A then the background will change to letter R instead of telling the user that they are wrong. basically I would like to know how I can stop the background from changing if the user does not enter the letter they are on here is the code.

     public void afterTextChanged(Editable s) {
                char ch = words.getText().toString().charAt(0);

                switch(ch - 'A') {

                case 0: 
                    //A;

                    gestureViewer.setBackgroundResource(R.drawable.lettersb);

                    break;
                case 1:
                    gestureViewer.setBackgroundResource(R.drawable.lettersc);
                    break;
                case 2:
                    gestureViewer.setBackgroundResource(R.drawable.lettersd);

                    break;
                case 3:
                    gestureViewer.setBackgroundResource(R.drawable.letterse);

                    break;
                case 4:
                    gestureViewer.setBackgroundResource(R.drawable.lettersf);
                    break;
                case 5:
                    gestureViewer.setBackgroundResource(R.drawable.lettersg);
                break;
                case 6:
                    gestureViewer.setBackgroundResource(R.drawable.lettersh);
                    break;
                case 7:
                    gestureViewer.setBackgroundResource(R.drawable.lettersi);
                    break;
                case 8:
                    gestureViewer.setBackgroundResource(R.drawable.lettersj);
                    break;
                case 9:
                    gestureViewer.setBackgroundResource(R.drawable.lettersk);
                    break;
                case 10:
                    gestureViewer.setBackgroundResource(R.drawable.lettersl);
                    break;
                case 11:
                    gestureViewer.setBackgroundResource(R.drawable.lettersm);
                    break;
                case 12:
                    gestureViewer.setBackgroundResource(R.drawable.lettersn);
                    break;
                case 13:
                    gestureViewer.setBackgroundResource(R.drawable.letterso);
                    break;
                case 14:
                    gestureViewer.setBackgroundResource(R.drawable.lettersp);
                    break;
                case 15:
                    gestureViewer.setBackgroundResource(R.drawable.lettersq);
                    break;
                case 16:
                    gestureViewer.setBackgroundResource(R.drawable.lettersr);
                    break;
                case 17:
                    gestureViewer.setBackgroundResource(R.drawable.letterss);
                    break;
                case 19:
                    gestureViewer.setBackgroundResource(R.drawable.letterst);
                    break;
                case 20:
                    gestureViewer.setBackgroundResource(R.drawable.lettersu);
                    break;
                case 21:
                    gestureViewer.setBackgroundResource(R.drawable.lettersv);
                    break;
                case 22:
                    gestureViewer.setBackgroundResource(R.drawable.lettersw);
                    break;
                case 23:
                    gestureViewer.setBackgroundResource(R.drawable.lettersx);
                    break;
                case 24:
                    gestureViewer.setBackgroundResource(R.drawable.lettersy);
                break;
                case 25:
                    gestureViewer.setBackgroundResource(R.drawable.lettersz);
                    break;

would it be better if I set the pictures in an array and then went from there? Ive tried including If switch case, but it didnt work at all….

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

    I’d pre-populae an array and invoke:

    gestureViewer.setBackgroundResource(myArray[ch - 'A']);
    

    It will make your code much more readable.

    You can also do it with a Map<Character,MyImage> – it might allow you to add more features easily in the future.

    If you do that, invokation will be using

    gestureViewer.setBackgroundResource(myMap.get(ch));
    

    Note that the array/map needs to be populated only once in the application’s runtime.

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

Sidebar

Related Questions

I've recently learned that python doesn't have the switch/case statement. I've been reading about
something driver me crazy here i have a big HTML template which i can't
I'm trying to find a way to have Resharper format a switch statement like
Just wondering what little scripts/programs people here have written that helps one with his
Since upgrading to 2008 I and many people here have noticed that randomly VS
I have an enum value as a member of a class which I want
I have a thread function on Process B that contains a switch to perform
I am writing some code in VB.NET that uses a switch statement but in
I need to declare the query variable outside the switch statement that way I
basically I have a pivot control in my WP7 app that contains 3 views.

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.