I am designing UI and for that need to populate some dummy content for recyclerview. So I thought to create using for loop so it makes life easier if I want to change the number.
I have drawable resources (images) that suffix with numbers. for instance
avatar_1, avatar_2, avatar_3, ...
featured_1, featured_2, featured_3, ...
I have tried setting R.drwable.featured_ + i and as expected it didn't work and end up with an error.
This is what I am using
...
for (int i = 0; i <= 11; i++) {
int username = random.nextInt(userNames.length);
int catInt = random.nextInt(categories.length);
int time = random.nextInt(times.length);
mBlogs.add(new Blog(
R.drawable.featured_ + i, // this
R.drawable.avatar_ + i, // this
getString(R.string.blog_title),
categories[catInt],
getString(R.string.blog_excerpt),
userNames[username],
times[time],
random.nextBoolean(),
random.nextBoolean()
));
}
...
Question: How can I get resource within the loop by loop index?