Issue
I have this list in an android Java file:
int[] imagelist = new int[]{R.drawable.n0d,R.drawable.n1d,R.drawable.n2d};
How can I make this list longer with a loop? In the end I'd like something like this:
int[] imagelist = new int[]{R.drawable.n0d,R.drawable.n1d,...,R.drawable.n85d};
Later I'd like to use it in a for loop, to display images in ImageViews:
int lenght = 3; //I'd like it to be: int lenght = 85;
for (int i=0;i<lenght;i++){
imageViews[i] = new ImageView(this);
imageViews[i].setImageResource(imagelist[i]);
imageViews[i].setLayoutParams(LayoutParamsview);
linearlayout.addView(imageViews[i]);
}
Solution
I've found the answer..! I used getIdentifier.
for (int i=0;i<lenght;i++){
imagelist[i] = getResources().getIdentifier("n"+(i)+"d","drawable",getPackageName());
}
Answered By - Atinator98
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.