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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:37:44+00:00 2026-05-17T16:37:44+00:00

Hey there. My app is going to be using an array of 64 ImageButtons

  • 0

Hey there. My app is going to be using an array of 64 ImageButtons (8×8), and they’re all already declared in my XML Layout with names like one1, two5, eight8, etc. Rather than declare these each individually in my Java I thought it might be smart to declare them all in some for loops. I have

ImageButton musicGrid[][] = new ImageButton [8][8];

Then I have my nested for loops that basically create a string that will be in place of R.id.whatever. It’s just that last line in my loops, that is supposed to do the assigning. What would the correct syntax for that be, or is this not even possible to do (and if so, how better would I handle a 64 button grid?). Thanks!

for (int i = 0; i < 8; i++) {
        for (int j = 0; j < 8; j++) {
            String btnID = "R.id.";
            switch(i) {
            case 0: btnID.concat("one"); break;
            case 1: btnID.concat("two"); break;
            case 2: btnID.concat("three"); break;
            case 3: btnID.concat("four"); break;
            case 4: btnID.concat("five"); break;
            case 5: btnID.concat("six"); break;
            case 6: btnID.concat("seven"); break;
            case 7: btnID.concat("eight"); break;
            }
            switch(j) {
            case 0: btnID.concat("1"); break;
            case 1: btnID.concat("2"); break;
            case 2: btnID.concat("3"); break;
            case 3: btnID.concat("4"); break;
            case 4: btnID.concat("5"); break;
            case 5: btnID.concat("6"); break;
            case 6: btnID.concat("7"); break;
            case 7: btnID.concat("8"); break;
            }
            musicGrid[i][j] = (ImageButton) findViewById(btnID);
        }
    }
  • 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-17T16:37:44+00:00Added an answer on May 17, 2026 at 4:37 pm

    I like AndrewKS’ for, it’s more elegant. Just keep in mind that findViewById receives an integer rather than a String. So you will have to do something like:

    int resID = getResources().getIdentifier(btnID, "drawable", "com.your.package");
    musicGrid[i][j] = (ImageButton) findViewById(resID);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey there, I've got a block of HTML that I'm going to be using
Hey all - I have an app where I'm authenticating the user. They pass
hey all i am using a webview in my android app. once i select
Hey, so I'm making an iPhone app and in there is a common function
Hey there, So I've been heavily focused on design/development using web technology for the
Hey I am making an app with the UIWebView and there are ajax things
hey there, i have written a custom control for my App so things get
Hey there, i have one question.. i try to write an android app with
Hey, I'm making an app where users should sometimes write numbers. Is there a
Hey I was wondering if there were any way to upload images in ASP?

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.