can not set gravity of text view through java code
<p>I am trying to set gravity of the text view through java in the following way </p>

<pre><code>if(check.equals("left")){           
        results.setGravity(Gravity.LEFT);           
    } else if(check.equals("center")){
        results.setGravity(Gravity.CENTER);
    } else if(check.equals("right")){
        results.setGravity(Gravity.RIGHT);
    }
</code></pre>

<p>But this does not work correctly.<br>
and in XML file the <code>gravity</code> is pre-set to <code>center</code>.<br></p>

<p>Here the results is TextView type variable .</p>

<p>this is the parent XML code:</p>

<pre><code>&lt;TextView android:id="@+id/textView1" 
 android:layout_width="fill_parent" 
 android:layout_height="wrap_content" 
 android:gravity="center" 
 android:text="Text" android:textSize="30dp" /&gt;
</code></pre>

<p><br>
Please help me
<br> And whole Layout XML code is</p>

<pre><code>&lt;EditText
    android:id="@+id/etCommands"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Type some commands"
    android:inputType="textPassword" &gt;

&lt;/EditText&gt;

   &lt;LinearLayout 
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:orientation="horizontal"
       android:weightSum="100"
       &gt;

&lt;Button
    android:onClick="cmdClick"
    android:layout_weight="20"
    android:id="@+id/bResults"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textSize="30dp"
    android:text="Try Commond" /&gt;

&lt;ToggleButton
    android:id="@+id/tgPassword"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:layout_weight="80"
    android:checked="true"
    android:paddingBottom="20dp"
    android:text="ToggleButton"
    android:onClick="togClick"
     /&gt;

 &lt;/LinearLayout&gt;


    &lt;TextView
       android:id="@+id/textView1"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"           
       android:gravity="center"
       android:text="Text" 
       android:textSize="30dp"
       /&gt;
</code></pre>

<p></p>
