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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:42:10+00:00 2026-05-18T20:42:10+00:00

i know that there must be a simpler way of doing this, i just

  • 0

i know that there must be a simpler way of doing this, i just don’t understand how java works well enough, and i am struggling. could someone perhaps point me in the right direction?

ImageButton image = (ImageButton) findViewById(R.id.card1);
    ImageButton image2 = (ImageButton) findViewById(R.id.card2);
    ImageButton image3 = (ImageButton) findViewById(R.id.card3);
    ImageButton image4 = (ImageButton) findViewById(R.id.card4);
    ImageButton image5 = (ImageButton) findViewById(R.id.card5);
    ImageButton image6 = (ImageButton) findViewById(R.id.card6);
    ImageButton image7 = (ImageButton) findViewById(R.id.card7);
    ImageButton image8 = (ImageButton) findViewById(R.id.card8);
    ImageButton image9 = (ImageButton) findViewById(R.id.card9);
    ImageButton image10 = (ImageButton) findViewById(R.id.card10);
    ImageButton image11 = (ImageButton) findViewById(R.id.card11);
    ImageButton image12 = (ImageButton) findViewById(R.id.card12);
    ImageButton image13 = (ImageButton) findViewById(R.id.card13);
    ImageButton image14 = (ImageButton) findViewById(R.id.card14);
    ImageButton image15 = (ImageButton) findViewById(R.id.card15);
    //image.setImageResource(R.drawable.test2);
    Bitmap bMap = BitmapFactory.decodeResource(getResources(), R.drawable.vraag);
    Bitmap bMapScaled = Bitmap.createScaledBitmap(bMap, buttonSize, buttonSize, true);
    Bitmap bMap2 = BitmapFactory.decodeResource(getResources(), R.drawable.vraag);
    Bitmap bMapScaled2 = Bitmap.createScaledBitmap(bMap2, buttonSize, buttonSize, true);
    Bitmap bMap3 = BitmapFactory.decodeResource(getResources(), R.drawable.vraag);
    Bitmap bMapScaled3 = Bitmap.createScaledBitmap(bMap3, buttonSize, buttonSize, true);
    Bitmap bMap4 = BitmapFactory.decodeResource(getResources(), R.drawable.vraag);
    Bitmap bMapScaled4 = Bitmap.createScaledBitmap(bMap4, buttonSize, buttonSize, true);
    Bitmap bMap5 = BitmapFactory.decodeResource(getResources(), R.drawable.vraag);
    Bitmap bMapScaled5 = Bitmap.createScaledBitmap(bMap5, buttonSize, buttonSize, true);
    Bitmap bMap6 = BitmapFactory.decodeResource(getResources(), R.drawable.vraag);
    Bitmap bMapScaled6 = Bitmap.createScaledBitmap(bMap6, buttonSize, buttonSize, true);
    Bitmap bMap7 = BitmapFactory.decodeResource(getResources(), R.drawable.vraag);
    Bitmap bMapScaled7 = Bitmap.createScaledBitmap(bMap7, buttonSize, buttonSize, true);
    Bitmap bMap8 = BitmapFactory.decodeResource(getResources(), R.drawable.vraag);
    Bitmap bMapScaled8 = Bitmap.createScaledBitmap(bMap8, buttonSize, buttonSize, true);
    Bitmap bMap9 = BitmapFactory.decodeResource(getResources(), R.drawable.vraag);
    Bitmap bMapScaled9 = Bitmap.createScaledBitmap(bMap9, buttonSize, buttonSize, true);
    Bitmap bMap10 = BitmapFactory.decodeResource(getResources(), R.drawable.vraag);
    Bitmap bMapScaled10 = Bitmap.createScaledBitmap(bMap10, buttonSize, buttonSize, true);
    Bitmap bMap11 = BitmapFactory.decodeResource(getResources(), R.drawable.vraag);
    Bitmap bMapScaled11 = Bitmap.createScaledBitmap(bMap11, buttonSize, buttonSize, true);
    Bitmap bMap12 = BitmapFactory.decodeResource(getResources(), R.drawable.vraag);
    Bitmap bMapScaled12 = Bitmap.createScaledBitmap(bMap12, buttonSize, buttonSize, true);
    Bitmap bMap13 = BitmapFactory.decodeResource(getResources(), R.drawable.vraag);
    Bitmap bMapScaled13 = Bitmap.createScaledBitmap(bMap13, buttonSize, buttonSize, true);
    Bitmap bMap14 = BitmapFactory.decodeResource(getResources(), R.drawable.vraag);
    Bitmap bMapScaled14 = Bitmap.createScaledBitmap(bMap14, buttonSize, buttonSize, true);
    Bitmap bMap15 = BitmapFactory.decodeResource(getResources(), R.drawable.vraag);
    Bitmap bMapScaled15 = Bitmap.createScaledBitmap(bMap15, buttonSize, buttonSize, true);

    image.setImageBitmap(bMapScaled);
    image2.setImageBitmap(bMapScaled2);
    image3.setImageBitmap(bMapScaled3);
    image4.setImageBitmap(bMapScaled4);
    image5.setImageBitmap(bMapScaled5);
    image6.setImageBitmap(bMapScaled6);
    image7.setImageBitmap(bMapScaled7);
    image8.setImageBitmap(bMapScaled8);
    image9.setImageBitmap(bMapScaled9);
    image10.setImageBitmap(bMapScaled10);
    image11.setImageBitmap(bMapScaled11);
    image12.setImageBitmap(bMapScaled12);
    image13.setImageBitmap(bMapScaled13);
    image14.setImageBitmap(bMapScaled14);
    image15.setImageBitmap(bMapScaled15);
  • 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-18T20:42:11+00:00Added an answer on May 18, 2026 at 8:42 pm

    I would probably use an array to make the code less messy. Try something like this:

    // UPDATE: change from String to int
    int[] imageIds = new int[15] {
      R.id.card1, R.id.card2, R.id.card3,
      R.id.card4, R.id.card5, R.id.card6,
      R.id.card7, R.id.card8, R.id.card9,
      R.id.card10, R.id.card11, R.id.card12,
      R.id.card13, R.id.card14, R.id.card15
    };
    
    // load the source image only once
    Bitmap bMap = BitmapFactory.decodeResource(getResources(), R.drawable.vraag);
    Bitmap bScaled = Bitmap.createScaledBitmap(bMap, buttonSize, buttonSize, true);
    
    // render them all
    ImageButton[] imageButtons = new ImageButton[15];
    for(int i = 0; i < imageButtons.size(); i++) {
      ImageButton button = imageButtons[i] = (ImageButton) findViewById(imageIds[i]);
      button.setImageBitmap(bMapScaled);
    }
    

    Good luck!

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

Sidebar

Related Questions

i know that there must be a simpler way of doing this, i just
I know there must be a simple way to do this but for the
I know there must be a better way to do this and I'm brain
I know that there must be some differences. I have a Silverlight component (
I know that there are some threads have a similar issue with this thread.
I know that there are lot's of questons on this, but all seem to
I know that there are lots of examples out there on this, but they
I want to know if there is a way to specify that in multiple
I know that there are others posts with solutions on the site but i
I know that there are currently questions on SO already pertaining to saving jQuery

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.