1

I have this array of drawables:

Integer[] mThumbIds = { R.drawable.celeb_0, R.drawable.celeb_1,
            R.drawable.celeb_2, R.drawable.celeb_3, R.drawable.celeb_4,
            R.drawable.celeb_5, R.drawable.celeb_6, R.drawable.celeb_7,
            R.drawable.celeb_8, R.drawable.celeb_9, R.drawable.celeb_10,
            R.drawable.celeb_11, R.drawable.celeb_12, R.drawable.celeb_13,
            R.drawable.celeb_14, R.drawable.celeb_15, R.drawable.celeb_16,
            R.drawable.celeb_17, R.drawable.celeb_18, R.drawable.celeb_19,
            R.drawable.celeb_20, R.drawable.celeb_21, R.drawable.celeb_22,
            R.drawable.celeb_23, R.drawable.celeb_24, R.drawable.celeb_25,
            R.drawable.celeb_26, R.drawable.celeb_27, R.drawable.celeb_28,
            R.drawable.celeb_29, R.drawable.celeb_30, R.drawable.celeb_31,
            R.drawable.celeb_32, R.drawable.celeb_33, R.drawable.celeb_34,
            R.drawable.celeb_35, R.drawable.celeb_36, R.drawable.celeb_37,
            R.drawable.celeb_38, R.drawable.celeb_39, R.drawable.celeb_40,
            R.drawable.celeb_41, R.drawable.celeb_42, R.drawable.celeb_43,
            R.drawable.celeb_44, R.drawable.celeb_45, R.drawable.celeb_46,
            R.drawable.celeb_47, R.drawable.celeb_48, R.drawable.celeb_49};

I want to replace the above code with some way of reading all the images in a specific drawable folder and inserting them into mThumbIds

or replace it with something like this:

 for (int i = 0; i < 50; i++) {
     mThumbIds[i] =R.drawable.celeb_i; // i is a variable in R.drawable.celeb_i
 }
8
  • what problem you are facing ? Commented Sep 28, 2014 at 9:30
  • i don't think it will work. Commented Sep 28, 2014 at 9:30
  • @ρяσѕρєяK I want the initialization of mThumbIds to be more dynamic and not static Commented Sep 28, 2014 at 9:33
  • @Waqleh : if mThumvIds size if not static then use Integer ArrayList instead of Array Commented Sep 28, 2014 at 9:35
  • @ρяσѕρєяK my issue is not with the size being dynamic, my issue is inserting R.drawable.celeb_i being dynamic as you can see the i is a variable. Commented Sep 28, 2014 at 9:43

1 Answer 1

1

I found the solution like so:

for (int i = 0; i < 50; i++) {
         mThumbIds[i] = mContext.getResources().getIdentifier("celeb_"+String.valueOf(i), "drawable", mContext.getPackageName());
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.