title: Dynamically adding an Android layout using for loop
body: <p>Ok so this is a method I use to draw a list of individual recipe steps using RelativeLayouts in a parent LinearLayout. The RelativeLayouts contain a TextView beside an Icon, which both should change with each i++. I can't find anything wrong with it, there are no errors or exceptions, the results just don't show. </p>
  
  <p>Is this the best way to do this? Is there a better way? Should I just learn how to use a ListView? Is it easier? Any help is appreciated.</p>
  
  <pre><code>    stepsList.setOrientation(LinearLayout.VERTICAL);
      for (int i=0; i==arrayLength; i++) {
          RelativeLayout stepsBlock = new RelativeLayout(getApplicationContext());
          ImageView recipeIcon = new ImageView(getApplicationContext());
          TextView recipeText = new TextView(getApplicationContext());
          RelativeLayout.LayoutParams blockParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
          RelativeLayout.LayoutParams iconParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
          RelativeLayout.LayoutParams textParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
          blockParams.setMargins(0, 2, 0, 0);
          if (i &gt; 0) {
              stepsBlock.setLayoutParams(blockParams);
          }
          stepsBlock.setPadding(3, 3, 3, 3);
          stepsBlock.setBackgroundColor(Color.parseColor("#b69878"));
  
          iconParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
          iconParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
          iconParams.setMargins(0, 0, 6, 0);
          recipeIcon.setBackgroundResource((com.package.app.R.drawable.iconwhite)+(i));
          recipeIcon.setLayoutParams(iconParams);
          recipeIcon.setId(1);
  
          textParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
          textParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
          textParams.addRule(RelativeLayout.RIGHT_OF, recipeIcon.getId());
          recipeText.setPadding(3, 3, 3, 3);
          recipeText.setText(recipeTinDough[i]);
          recipeText.setTextSize(12);
          recipeText.setTextColor(Color.BLACK);
          recipeText.setLayoutParams(textParams);
          recipeText.setId(2);
  
          stepsList.addView(stepsBlock);
          stepsBlock.addView(recipeIcon);
          stepsBlock.addView(recipeText);
  
      }
  }
  </code></pre>