1

I have 100+ images to load into a listView, and I am trying to store all the resId into an int[]. I can done it from drawable by using the below code

Field[] ID_Fields = R.drawable.class.getFields();
        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();
            } catch (IllegalAccessException e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

But my problem is that I don't need all images in the drawable folder for my listView. So can i create a folder inside the asset and get all resId into a int[] ? or can I use raw folder for this? Any help will be appreciated.

Alex Chengalan
  • 8,211
  • 4
  • 42
  • 56
  • what do you exactly want. question is not clear enough – stinepike May 08 '13 at 05:17
  • Are you asking for suggestion or code? – Pragnani May 08 '13 at 05:20
  • if I am use the above code, i will get all the images resId into the array.. Actually I dont need that,, It is little big project and so the drawable contains other designing and background images also. I only wants some of drawable images into the listview. and also we cant create folder inside the drawable. So I am trying to use asset folder – Alex Chengalan May 08 '13 at 05:21
  • Or can i use raw folder instead of drawable? – Alex Chengalan May 08 '13 at 05:25

2 Answers2

1

I got the answer.

YES we can do it. Copy the images into res/raw folder and try with this code

Field[] ID_Fields = R.raw.class.getFields();
        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();
            } catch (IllegalAccessException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }


        }

After that resArray contains the resId of the images in the raw folder

Alex Chengalan
  • 8,211
  • 4
  • 42
  • 56
0

It is possible..but It is not a good way for you. You can put images in Asset folder Like this See Here

but if you do this there can be issues created Issues

So now it is up to you how you use it. :)

Community
  • 1
  • 1
Mit Bhatt
  • 1,605
  • 2
  • 13
  • 24