Sunday, 27 January 2013

Creating Layout Dynamically in Android


MainActivity.java:
package com.dynamiclayout.ram;

import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MainActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
TextView t1 = new TextView(this);
t1.setText("sample text");
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
ll.addView(t1);
setContentView(ll);
}

}

No comments:

Post a Comment