I am trying to add several custom ViewGroups dynamically to an existing RelativeLayout through a ForLoop.
When I add them, nothing is displayed. Maybe it's because the ViewGroup isn't finished loading before it's added?
Anyway to fix this?
Thank you,
GameActivity.java:
hScrollItems = (RelativeLayout) findViewById(R.id.hScrollItems);
    for (int i = 0; i < 5; i++){
        int w = getResources().getInteger(R.integer.GridItemWidth);
        int h = getResources().getInteger(R.integer.GridItemWidth);
        GridItem gi = new GridItem(getBaseContext(), w, h, GridType.EMPTY);
        LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        params.setMargins(w * i, 0, 0, 0);
        hScrollItems.addView(gi, params);
    }
GridItem.java
public GridItem(Context context, int Width, int Height, GridType Type) {
    super(context);
    /*LayoutParams params = new LayoutParams(Width, Height);
    this.setLayoutParams(params);*/
    this.setBackgroundColor(0xFFFFFF33);
    ImageView img = new ImageView(context);
    img.setBackgroundResource(R.drawable.ic_launcher);
    this.addView(img);
}
public enum GridType {
    EMPTY("EMPTY"),
    HOUSE("HOUSE");
    private String value;
    private GridType(String value) {
       this.value = value;
    }
    public String getValue() {
       return value;
    }
}
 
     
    