Creating Android TextView programmatically

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
	xmlns:android="http://schemas.android.com/apk/res/android"
	android:layout_width="match_parent"
	android:layout_height="match_parent"
	android:id="@+id/myLinear1">

</LinearLayout>

MainActivity.java

package com.mycompany.myapp;

import android.app.*;
import android.graphics.*;
import android.os.*;
import android.view.*;
import android.widget.*;

public class MainActivity extends Activity 
{
	LinearLayout myLinear1;
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
		
		myLinear1 = findViewById(R.id.myLinear1);
		
		final TextView myText1 = new TextView(MainActivity.this);
		myText1.setText("I was created dynamically");
		myText1.setTextColor(Color.RED);
		myText1.setTextSize(23);
		
		myLinear1.addView(myText1);
    }
}