Pages

Sunday, May 22, 2016

Creating Layout Dynamically in Android

MainActivity.java
package com.blogspot.kantapp.creatinglayoutdynamicallyinandroid;

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