A little bit about layout inflater. loading layouts dynamically.

satya komatineni layout inflater

Search for: satya komatineni layout inflater


public class Uncscramble1Activity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        setup1();
    }
    private void setup1()
    {
    	LinearLayout buttonParentLayoutView
    	= (LinearLayout)this.findViewById(R.id.buttonParentLayoutView);
    	
    	LayoutInflater li = this.getLayoutInflater();
    	Button b1 =
    	(Button)li.inflate(R.layout.button_layout, null);
    	b1.setText("A");

    	Button b2 =
        	(Button)li.inflate(R.layout.button_layout, null);
        	b2.setText("B");
    	
    	buttonParentLayoutView.addView(b1);
    	buttonParentLayoutView.addView(b2);
    }
}

<?xml version="1.0" encoding="utf-8"?>
<Button 
xmlns:android="http://schemas.android.com/apk/res/android">
android:text="Button" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
</Button>

you will need to keep track of the loaded views through pointers. Any time you hold stuff in pointers, beware of device rotation.