We have to use "new" keyword to create objects dynamically
public class DynamicViews extends Activity { LinearLayout L1, L2; // Created in xml LinearLayout L3; // Created dynamically in java using "new" operator TableLayout TL; // Created in xml; TableRow tr1, tr2, tr3; // Created dynamically in java using "new" operator TextView t1, t2, t3, t4; // Created dynamically in java using "new" operator @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); <-- setContentView( int ); --> <-- Get L1 from xml --> <-- Get L2 from xml --> t1 = new TextView(this); <-- t1.setters() --> L2.addView(t1); L3 = new LinearLayout(this); <-- L3.setters() --> L3.setOrientation(LinearLayout.VERTICAL); <-- Get TL from xml --> tr1 = new TableRow(this); tr2 = new TableRow(this); t2 = new TextView(this); <-- t2.setters() --> tr1.addView(t2); t3 = new TextView(this); <-- t3.setters() --> L3.addView(t3); t4 = new TextView(this); <-- t4.setters() --> L3.addView(t4); tr2.addView(L3); TL.addView(tr1); TL.addView(tr2); TL.addView(tr3); } }