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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:00:07+00:00 2026-05-26T15:00:07+00:00

Using java for Android development. I have an array that stores image resources. The

  • 0

Using java for Android development.

I have an array that stores image resources. The image resources are named in numerical order (1.png, 2.png, etc). I would like to use a for loop to create the values in the array instead of declaring each value individually.

What I have tried:

 private int[] myArray = {R.drawable.r1, R.drawable.r2, etc};

What I would like to do:

 private int[] myArray;
 myArray = new int[50]
 for (i=0; i<50; i++) {
 myArray[i] = R.drawable. + "i"
  • 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-26T15:00:08+00:00Added an answer on May 26, 2026 at 3:00 pm

    Well this sort of thing is technically possible, but is prone to certain issues. The R class is dynamically generated. While its moderately predictable, if for some reason your generated values change it could completely break your code. However, if you were to do this it would look like this:

     private int[] myArray;
     myArray = new int[50];
     int id = R.drawable.firstImage;
     for (i=0; i<50; i++) {
        myArray[i] = id + i;
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have starting learning Java and android application development side-by-side. Currently, I a String-array
I'm dipping my toes into Android development. I have a project that will interface
I am a C#/.Net developer who just began Java development for Android, and using
Today I have started with setting up of Android Development Environment using Eclipse for
I have been using Eclipse for Android development and don't have a problem with
Just started using Java (for Android, if that matters) and all I want is
I made an android project using eclipse. It looks like: src/ ActivityMain.java lib/ Square.java
Using Java, how can I test that a URL is contactable, and returns a
Using Java (1.6) I want to split an input string that has components of
By using java reflection, we can easily know if an object is an array.

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.