title: How to create simple Android TextView and display text on it using java code?
body: <p>I have created a sample project and run 'Hello Android Application' in Eclipse.</p>
  
  <p>I have learned that a Textview can be created in two ways, either using an XML tag or by using Java code.</p>
  
  <p>By default I have one Textview saying "Hello world" in my sample project. I want to create a Textview using Java code and display some message on it.</p>
  
  <p>I have searched a lot, but I am unable to understand the steps and layout settings mentioned in the code.</p>
  
  <p>This is what I have done:</p>
  
  <pre><code>import android.app.Activity;
  import android.view.Menu;
  import android.view.ViewGroup;
  import android.widget.*;
  import android.view.View;
  
  public class MainActivity extends Activity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          LinearLayout.LayoutParams params = 
                  new LinearLayout.LayoutParams( 
                     ViewGroup.LayoutParams.WRAP_CONTENT, 
                     ViewGroup.LayoutParams.WRAP_CONTENT, 0.0F);
  
          TextView tx= new TextView(this);
  //      tx.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
          tx.setText("ANDROID APP");
          lay
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.activity_main, menu);
          return true;
      }
  }
  </code></pre>
  
  <p>Further I don't know how to add this textview in <code>addView()</code>.</p>
  
  <p>This is my <code>activity_main.xml</code>:</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context=".MainActivity" &gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>A step by step solution would be helpful for me and any good tutorial link would be appreciable. Thank you in advance!</p>