I have a folder named first - res/drawable/pics/first
.The folder can contain upto 5 images(5 or less than 5).I need to loop through all these images and add to this slider https://github.com/daimajia/AndroidImageSlider
Is something like this possible?
x=5;
sliderShow1 = (SliderLayout)findViewById(R.id.ad1);
TextSliderView[] textSliderViewarray=new TextSliderView[x];
for (int y=0;y<x;y++)
{
textSliderViewarray[y]=new TextSliderView(this);
}
for (int y=0;y<x;y++)
{
textSliderViewarray[y].description(" ").image("@drawable/pics/first/"+Integer.toString(y+1)+".png");
sliderShow1.addSlider(textSliderViewarray[y]);
}
This code creates 5 sliders with blank content.
Try this:
The root folder of the images should be drawable. Don't keep in nested folders.
Use the following code:
for (int y=0;y<x;y++)
{
// Assuming image names as 1.png, 2.png, 3.png ...
String resourceName = Integer.toString(y); // Extension is not needed.
int resourceId = getResources().getIdentifier(resourceName, "drawable", getPackageName());
textSliderViewarray[y].description(" ").image(resourceId);
sliderShow1.addSlider(textSliderViewarray[y]);
}