Your code block shows an Article class that is supposed to be attached to the RecyclerView with a corresponding image, is what I assume from your question.
In your comments you have
for (int i = 0; i < 30; ++i) { articles.add(new Article(i))}
- You set 30 as a hard coded limit instead you should set it to the size of your image id array.
- You're aware that you're incrementing your index before you add the article which will cause you to lose out on the id at index 0.
- All this does is pass an
int through your constructor to grab the id at that array index in your Article class you should not have a static array of images in an object class.
Change your Article class to look like this:
public class Article {
...
int imageID;
public Article(int imageID) {
this.imageID = imageID;
}
public int getImageID() {
return imageID;
}
...
}
Now when you loop through and add your articles it should like like this:
for (int i = 0; i < imageIDArray.length; i++) {
articles.add(new Article(imageIDArray[i]);
}
Now you're setting the imageID to be whatever value is in your imageIDArray once you're in the onBindViewHolder() method of your RecyclerView you can then easily set the correct image by using
setImageDrawable(ContextCompat.getDrawable(context, article(i).getImageID));