This code snippet will generate the textview and button at run time.
//The layout LinearLayout01 should be predefined.In this layout you add all the controls
LinearLayout layout = (LinearLayout) findViewById(R.id.LinearLayout01);
for (int i = 2; i < 6; i++)
{
TextView textView = new TextView(this);
//You can set the value depending on the condition
textView.setText("Text View " + i);
LinearLayout.LayoutParams p = new
LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT
);
layout.addView(textView, p);
Button buttonView = new Button(this);
buttonView.setText("Button " + i);
layout.addView(buttonView, p);
}

