0

I have an array contains string values, in that same name i have image in drawable.so i want to add in integer array how to do that? ex string newarray[]={"jj","kk","ll"}; i want to access R.drawable.jj ,R.drwable.kk,R.drawable.ll

bamini
  • 99
  • 3
  • 11

2 Answers2

2

To access the drawables you need an int. Instead of saving the names in a String array, save the IDs in an int array:

int[] drawables = {R.drawable.jj, R.drawable.kk, R.drawable.ll};

Then all you need to do to access them is call:

getResources().getDrawable(drawables[0]);
TofferJ
  • 4,678
  • 1
  • 37
  • 49
  • i have n number of string values which am taking according to my list selection for example if i select firstitem array value will change.in that case how to do this – bamini May 17 '11 at 13:04
  • I think what he meant is what WarrenFaith answered. – neteinstein May 17 '11 at 13:44
  • I have four images in the Gallery View. When we do swipe from left to right or right to left the Gallery View moves all the images i.e if I swipe from left to right from the first image then it will move to all the four images. What I want is that when I swipe it should only move to the next image. – bamini May 18 '11 at 09:50
1

You could try to get the identifier by name:

Resources res = getResources();
res.getDrawable(res.getIdentifier(myStringArray[0], "drawable", myPackage));

A similar question was already answered: get resource id by passing name as a parameter in android

Community
  • 1
  • 1
WarrenFaith
  • 57,492
  • 25
  • 134
  • 150
  • I have four images in the Gallery View. When we do swipe from left to right or right to left the Gallery View moves all the images i.e if I swipe from left to right from the first image then it will move to all the four images. What I want is that when I swipe it should only move to the next image. – bamini May 18 '11 at 09:50
  • this is quite another question and I guess that it was already asked here. please search for it. A suggestion: If you implement the gesturedetector, you should be able to define how much the gallery should move. Anyway, search for it, I bet this was already asked and answered here... – WarrenFaith May 18 '11 at 10:23