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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:23:27+00:00 2026-06-17T22:23:27+00:00

My game needs to update the background of a TextView in every class onCreate

  • 0

My game needs to update the background of a TextView in every class onCreate to show the health of the player, however at the moment the only way i can think of doing it is this

int Health = 100;

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_act1);

    if (Health == 100){
        HealthDisplay.setBackgroundResource(R.drawable.health100);
    } else if (Health == 99){
        HealthDisplay.setBackgroundResource(R.drawable.health99);
    } else if (Health == 98){
        HealthDisplay.setBackgroundResource(R.drawable.health98);
    } else if (Health == 99){
        HealthDisplay.setBackgroundResource(R.drawable.health98);
    } else if (Health == 99){
        HealthDisplay.setBackgroundResource(R.drawable.health98);
    } else if (Health == 99){
        HealthDisplay.setBackgroundResource(R.drawable.health98);
    }

etc.
}

There has to be an easier/ faster way of doing this, especially as i need to do similar for two other stats as well.

I have thought about having a separate class handle it and have a line or two in the onCreate that tells it to run that class to update the background image then return to this one.

Alternatively perhaps something like this is possible?

int Health = 100;

HealthDisplay.setBackgroundResource(R.drawable.health(Health));
  • 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-17T22:23:28+00:00Added an answer on June 17, 2026 at 10:23 pm

    What I would suggest is having one image (for full health) and each time crop it and show a percentage of it according to your health level. For example:

    private ImageView healthLevel;
    private ClipDrawable clipDrawable;
        @Override
            public void onCreate(Bundle savedInstanceState) {
                healthLevel = (ImageView ) findViewById(R.id.health);   //there a corresponding ImageView in the layout
                BitmapDrawable bitmapDrawable = new BitmapDrawable(BitmapFactory.decodeResource(getResources(),    R.drawable.full_health));
                //vertical bar cropped from top
                clipDrawable = new ClipDrawable(bitmapDrawable, Gravity.BOTTOM, ClipDrawable.VERTICAL);  
                healthLevel.setImageDrawable(clipDrawable);
        }
    

    and then in another thread you would call:

    int health = 54;
    clipDrawable.setLevel(health);
    clipDrawable.invalidateSelf();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to simulate a game where each player has turns and needs to
I've started a Breakout game in Canvas . At the moment, I've only coded
I am making a game that needs a crosshair. I have been playing with
I have a WP7 XNA game that needs to save the state whenever the
I'm a new iOS programming and I'm developing a simple iPhone game that needs
For the needs of my game I need to have 2D sound. That means,
Trying to make an xna game, where the user needs to tap to stop
Scenario : I am making a clone of a popular card game. There needs
I have a game in XNA which needs to do network calls. In the
I am working on a game in Construct2 at the moment. It is a

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.