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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:51:42+00:00 2026-05-28T19:51:42+00:00

Basically I want to switch between the drawable resources, and I cant figure out

  • 0

Basically I want to switch between the drawable resources, and I cant figure out how I would go about doing it. I wrote it all in an If statement but its too long and messy and its not executing the way I want to because it doesnt stop if they enter the wrong letter.

What I am trying to do is if the user enters a letter, the background will change to the next letter after that for instance, If the user enters A the background will change to B, so on and so on. It does work right now, But what is wrong is that If the user is on the letter A and the user enters the letter P by mistake the background will switch to Q rather than telling the user they are wrong.

I did have this code as an else if rather than just If statements but i just figured I would change it today. Can anyone explain how I would put this If statement into a case statement? Thank you for your help

             if (words.getText().toString().equalsIgnoreCase("A")) {

                gestureViewer.setBackgroundResource(R.drawable.lettersb);

            } else {
             onDestroy();
            } 
             if (words.getText().toString().equalsIgnoreCase("B")) {
                gestureViewer.setBackgroundResource(R.drawable.lettersc);
            } else {
            }
             if (words.getText().toString().equalsIgnoreCase("C")) {
                gestureViewer.setBackgroundResource(R.drawable.lettersd);
            } else {
            }
             if (words.getText().toString().equalsIgnoreCase("D")) {
                    gestureViewer.setBackgroundResource(R.drawable.letterse);
            } else {
            }
             if 
                (words.getText().toString().equalsIgnoreCase("E")) {
                    gestureViewer.setBackgroundResource(R.drawable.lettersf);
            } else {
            }
                if (words.getText().toString().equalsIgnoreCase("F")) {
                    gestureViewer.setBackgroundResource(R.drawable.lettersg);

            } else {
            }
                if (words.getText().toString().equalsIgnoreCase("G")) {
                    gestureViewer.setBackgroundResource(R.drawable.lettersh);
            }else {
            }
                if (words.getText().toString().equalsIgnoreCase("H")) {

                    gestureViewer.setBackgroundResource(R.drawable.lettersi);
            }else {
            }
                if (words.getText().toString().equalsIgnoreCase("I")) {
                    gestureViewer.setBackgroundResource(R.drawable.lettersj);
            } else {
            }
                if (words.getText().toString().equalsIgnoreCase("J")) {
                    gestureViewer.setBackgroundResource(R.drawable.lettersk);
            }else {
            }
                if (words.getText().toString().equalsIgnoreCase("K")) {
                    gestureViewer.setBackgroundResource(R.drawable.lettersl);
            }else {
            }
                if (words.getText().toString().equalsIgnoreCase("L")) {
                    gestureViewer.setBackgroundResource(R.drawable.lettersm);
            }else {
            }
                if (words.getText().toString().equalsIgnoreCase("M")) {
                    gestureViewer.setBackgroundResource(R.drawable.lettersn);
            }else {
            }
                if (words.getText().toString().equalsIgnoreCase("N")) {
                    gestureViewer.setBackgroundResource(R.drawable.letterso);
            }else {
            }
                if (words.getText().toString().equalsIgnoreCase("O")) {
                    gestureViewer.setBackgroundResource(R.drawable.lettersp);
            }else {
            }
                if (words.getText().toString().equalsIgnoreCase("P")) {
                    gestureViewer.setBackgroundResource(R.drawable.lettersq);
            }else {
            }
                if (words.getText().toString().equalsIgnoreCase("Q")) {
                    gestureViewer.setBackgroundResource(R.drawable.lettersr);
            } else {
            }
                if (words.getText().toString().equalsIgnoreCase("R")) {
                    gestureViewer.setBackgroundResource(R.drawable.letterss);
            } else  {
                    }

                if (words.getText().toString().equalsIgnoreCase("S")) {

                    gestureViewer.setBackgroundResource(R.drawable.letterst);
            }else {

            }

                if (words.getText().toString().equalsIgnoreCase("T")) {
                    gestureViewer.setBackgroundResource(R.drawable.lettersu);
            }else {

            }

                if (words.getText().toString().equalsIgnoreCase("U")) {
                    gestureViewer.setBackgroundResource(R.drawable.lettersv);
            }else {

            }
                if (words.getText().toString().equalsIgnoreCase("V")) {
                    gestureViewer.setBackgroundResource(R.drawable.lettersw);
            }else {

            }
                if (words.getText().toString().equalsIgnoreCase("W")) {
                    gestureViewer.setBackgroundResource(R.drawable.lettersx);
            }else {

            }
                if (words.getText().toString().equalsIgnoreCase("X")) {
                    gestureViewer.setBackgroundResource(R.drawable.lettersy);
            }else {

            }
                if (words.getText().toString().equalsIgnoreCase("Y")) {
                    gestureViewer.setBackgroundResource(R.drawable.lettersz);
            }else {

            }
                if (words.getText().toString().equalsIgnoreCase("Z")) {
                    gestureViewer.setBackgroundResource(R.drawable.lettersa);

            } else {

            }
         }
         public void beforeTextChanged(CharSequence s, int start, int count, int after){

         }
         public void afterTextChanged(Editable s) {


         } 
});

    }
  • 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-28T19:51:44+00:00Added an answer on May 28, 2026 at 7:51 pm

    use following

    char ch=words.getText().toString().charAt(0));
    
        switch(ch-'A')
        {
          case 0:
               //A;
               break;
          case 1:
               //B;
               break;
        .....
        }
    

    By this you can convert if statements to switch case:

    Also you can have drawable array, then you wont need to use switch case also:

    int[] arr=new int[]{R.id.drawable_A, .......};
    

    then setting color would be

    char ch=words.getText().toString().charAt(0));
    int index=ch-'A';
    view.setBackgroundResource(index);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just basically want to add about 20 and sometimes 80 Proximity Alerts with
I basically want to do this: switch($someString.ToLower()) { y, yes { You entered Yes.
Basically what I want to do is be able to set a switch somewhere:
I have a page which basically loads using ajax, but I want to switch
The title basically says it all. Suppose I have an element which I want
I want to be able to switch between a UITableView and a standard UIView
I basically want to use link_to to link to the index method of a
I basically want to do this: grep 'example.com' www_log > example.com.YYYY-MM-DD-H:i:S.log ...with of course
I basically want to do this in code: PersonList myPersonList; //populate myPersonList here, not
I basically want to be able to deploy multiple versions of the same EAR

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.