Im trying to create a bunch of ImageViews In a For loop. I want to set the views below each other. For that i thought of setting the id for the views to the i value of the for loop and then set a LayoutParam BELOW to the id of i-1.
for (int i = 0; i < a.length(); i++)
{
ImageView img = new ImageView(this);
img.setImageResource(R.drawable.board);
img.setId(i);
RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) img.getLayoutParams();
lp.addRule(RelativeLayout.BELOW, i-1);
img.setLayoutParams(lp);
}
This provides a problem when i isn't 0. I then get the warning "expected resource of type id" which i read countless places is easily solved by View.generateViewId()
however this generates a random id therefore i can't reach the previous id on the next loop.
How could one go about this?
however this generates a random id therefore i can't reach the previous id on the next loop.
Store the id values or the whole ImageView objects in an Arraylist.
Then you either can lookup previous id or just use the generate method like its meant to, and use the getId method on the view itself.
Or forget it all, and use a vertical LinearLayout