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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:10:34+00:00 2026-06-10T20:10:34+00:00

there are many images in drawable foder so instead manually creating array of all

  • 0

there are many images in drawable foder so instead manually creating array of all image resource ids , i want to get all images dynamically of drawable folder in array.
currently i m using this code:

for(int i=1;i<=9;i++)
    {
            int imageKey = getResources().getIdentifier("img"+i, "drawable", getPackageName());
            ImageView image = new ImageView(this);  
            image.setId(imgId);
            image.setImageResource(imageKey);    
            image.setScaleType(ImageView.ScaleType.FIT_XY);
            viewFlipper.addView(image, new LayoutParams(LayoutParams.FILL_PARENT,              LayoutParams.FILL_PARENT));
            imgId++;
        }

but in that code i need to manually edit the image name to get the resource id but i want to get all image with any name..

  • 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-10T20:10:36+00:00Added an answer on June 10, 2026 at 8:10 pm

    you can Use Reflection to achieve this.

    import the Field class

    import java.lang.reflect.Field;

    and then write this in your code

    Field[] ID_Fields = R.drawable.class.getFields();
    int[] resArray = new int[ID_Fields.length];
    for(int i = 0; i < ID_Fields.length; i++) {
        try {
            resArray[i] = ID_Fields[i].getInt(null);
        } catch (IllegalArgumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    

    resArray[] now holds references to all the drawables in your application.

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

Sidebar

Related Questions

I'm using the following code to load many images into an array, but want
Suppose we have classes Gallery and Image. There can be many images in one
my Page has many hover images, sometimes there are backgrounds from div-elements or src
I have a simple setup, where there are Products and Images. Products have many
I have been JQuery UI Slider with content and there are many images in
At http://hollywoodnose.com I have conditional ads based on how many images there are for
I want to be able to load images dynamically from res/drawable. I don't how
I have many images inside of a scrolling DIV for an image gallery and
I want to extract many images from a large PDF and then display those
In my WPF app I have many images of books which i want to

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.