title: changing textView's layout gravity
body: <p>I have a <code>TextView</code> in a <code>ListView</code>. I am trying to change the alignment of the <code>textview</code> according to the corresponding text. But it is not working. </p>
  
  <p>Thanks</p>
  
  <pre><code>if (stringItem != null) {
          TextView messageText = (TextView) view.findViewById(R.id.list_item_text_view);
  
           if (mine==0)
               messageText.setGravity(Gravity.RIGHT);            
  
           if (mine==1)    
               messageText.setGravity(Gravity.LEFT);
  
       messageText.setText(stringItem);   
  } 
  </code></pre>
  
  <p>and my Layout is as follow: </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/list_item"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:gravity="center_vertical"
  android:orientation="vertical" &gt;
  
  &lt;TextView
      android:id="@+id/list_item_text_view"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginLeft="5dp"
      android:layout_marginRight="10dp"
      android:layout_marginTop="10dp"
      android:layout_marginBottom="10dp"
      android:background="@drawable/self_textview"
      android:textSize="20sp" /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>*<em>EDIT: *</em> I know how to change it from the <code>xml</code> file, but how to change it from code ? </p>
  
  <pre><code>android:layout_gravity="right"
  </code></pre>