title: How to align the textView to right or left based on the values from database
body: <p>i am new to android programing. i am developing a android mobile application where data will be coming from mysql database and on the based on the logged in user, i want to shift the textview to the right and rest values on the left. For now i am only trying to move the "rahul" values on the right.</p>
  
  <p>JSON Values:</p>
  
  <pre><code>[{
      "user": "varun",
      "message": "hello word, my first message "
  }, {
      "user": "varun",
      "message": "hello word, my first message "
  }, {
      "user": "rahul",
      "message": "hello world"
  }, {
      "user": "rahul",
      "message": "world: its cool"
  }, {
      "user": "rahul",
      "message": "awesom"
  }, {
      "user": "rahul",
      "message": "ranom"
  }, {
      "user": "rahul",
      "message": "randimagain"
  }, {
      "user": "rahi",
      "message": "is it me again"
  }, {
      "user": "rahull",
      "message": "hi rahul"
  }, {
      "user": "rahul",
      "message": "world, am bacj"
  }, {
      "user": "rahul",
      "message": "hello parents"
  }, {
      "user": "",
      "message": ""
  }, {
      "user": "",
      "message": ""
  }, {
      "user": "",
      "message": ""
  }, {
      "user": "",
      "message": ""
  }, {
      "user": "",
      "message": ""
  }, {
      "user": "varun",
      "message": "google world"
  }, {
      "user": "rahul",
      "message": "ollaaa"
  }, {
      "user": "rahul",
      "message": "ollaaa"
  }, {
      "user": "rahul",
      "message": "where are others"
  }, {
      "user": "rahul",
      "message": "where are others"
  }, {
      "user": "varun",
      "message": "oil spil"
  }, {
      "user": "varun",
      "message": "phone"
  }, {
      "user": "vatun",
      "message": "tttt"
  }, {
      "user": "varun",
      "message": "poiuytrew"
  }, {
      "user": "rahui",
      "message": "yregh"
  }, {
      "user": "varun",
      "message": "huiokgddfv"
  }, {
      "user": "rahi",
      "message": "poiutghklnbfd"
  }, {
      "user": "rahui",
      "message": "qwerty"
  }, {
      "user": "varub",
      "message": "hi eat pineapple"
  }, {
      "user": "varun",
      "message": "hi prabh"
  }, {
      "user": "rahul",
      "message": "hi world"
  }, {
      "user": "ggjdjjf",
      "message": "yhvdhhj"
  }, {
      "user": "tgggg",
      "message": "hhhh"
  }, {
      "user": "rahul",
      "message": "lqvrl"
  }, {
      "user": "hhhh",
      "message": "ghh"
  }, {
      "user": "tff",
      "message": "gg"
  }, {
      "user": "hfdhn",
      "message": "hnnnme"
  }, {
      "user": "popo",
      "message": "plpl"
  }, {
      "user": "rahulpop",
      "message": "op music"
  }, {
      "user": "rtrt",
      "message": "tyty"
  }, {
      "user": "hlpo",
      "message": "opop"
  }, {
      "user": "hlpoghhj",
      "message": "opop"
  }, {
      "user": "tt",
      "message": "hhh"
  }, {
      "user": "ttere",
      "message": "hhh"
  }, {
      "user": "gytgjyg",
      "message": "lajdhd"
  }, {
      "user": "topo",
      "message": "ptpt"
  }, {
      "user": "jgj",
      "message": "rtr"
  }, {
      "user": "ry",
      "message": "yr"
  }, {
      "user": "ry",
      "message": "yr"
  }, {
      "user": "y",
      "message": "q"
  }, {
      "user": "u",
      "message": "t"
  }, {
      "user": "tt",
      "message": "pp"
  }, {
      "user": "q",
      "message": "z"
  }, {
      "user": "w",
      "message": "v"
  }, {
      "user": "e",
      "message": "e."
  }, {
      "user": "ui",
      "message": "ui"
  }, {
      "user": "yi",
      "message": "yi"
  }, {
      "user": "gg",
      "message": "g"
  }, {
      "user": "e",
      "message": "e"
  }, {
      "user": "h",
      "message": "hh"
  }, {
      "user": "j",
      "message": "j"
  }, {
      "user": "j",
      "message": "k"
  }, {
      "user": "v",
      "message": "v"
  }, {
      "user": "ty",
      "message": "ewr"
  }] 
  </code></pre>
  
  <p>currently what is happeing, all the data is coming on the left side in a listview. Looking for a solution where i can move the "rahul" username values to the right like a chat application.</p>
  
  <p>COde for displaying values:</p>
  
  <pre><code>package com.weavearound.schools.weavearound;
  
  import android.graphics.Color;
  import android.support.v7.app.ActionBarActivity;
  import android.os.Bundle;
  import android.support.v7.app.AppCompatActivity;
  import android.util.Log;
  import android.view.Gravity;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.AbsListView;
  import android.widget.ArrayAdapter;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.LinearLayout;
  import android.widget.ListView;
  import android.widget.TextView;
  
  import com.android.volley.AuthFailureError;
  import com.android.volley.Request;
  import com.android.volley.RequestQueue;
  import com.android.volley.Response;
  import com.android.volley.VolleyError;
  import com.android.volley.toolbox.JsonArrayRequest;
  import com.android.volley.toolbox.StringRequest;
  import com.android.volley.toolbox.Volley;
  import com.weavearound.schools.weavearound.R;
  
  import org.json.JSONArray;
  import org.json.JSONException;
  import org.json.JSONObject;
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.Map;
  
  public class ListViewNew extends AppCompatActivity {
  
      EditText username, messsage;
      Button insert, show;
      RequestQueue requestQueue1;
      String insertUrl = "http://www.schools.weavearound.com/chatdb_api/insert.php";
      TextView value;
  
      ArrayAdapter&lt;String&gt; adapter;
      ArrayList&lt;String&gt; items;
  
      //ArrayAdapter&lt;String&gt; adapter1;
      //ArrayList&lt;String&gt; items1;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
  
  
          username = (EditText) findViewById(R.id.editText3);
          messsage = (EditText) findViewById(R.id.editText2);
          insert = (Button) findViewById(R.id.button);
          show = (Button) findViewById(R.id.button2);
  
  
  
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_blabla);
          ListView listView = (ListView) findViewById(R.id.listv);
  
  
  
          items = new ArrayList&lt;String&gt;();
          adapter = new ArrayAdapter(this, R.layout.item_layout, R.id.txt, items);
          listView.setAdapter(adapter);
  
          //items1 = new ArrayList&lt;String&gt;();
          //adapter1 = new ArrayAdapter(this, R.layout.item_layout, R.id.txtright, items1);
  
          //listView.setAdapter(adapter1);
  
      }
          //listView.setBackgroundResource(R.drawable.border);
  
  
      public void onStart() {
          super.onStart();
          // Create request queue
          RequestQueue requestQueue = Volley.newRequestQueue(this);
          //  Create json array request
          JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.POST, "http://www.schools.weavearound.com/chatdb_api/showback.php", new Response.Listener&lt;JSONArray&gt;() {
              public void onResponse(JSONArray jsonArray) {
  
                  String data = "";
                  String message = "";
                  String result="";
                  String value ="";
                  // Successfully download json
                  // So parse it and populate the listview
  
                  final String TAG = events.class.getSimpleName();
                  Log.d(TAG, "showJSON: \n" + jsonArray);
  
                  for (int i = 0; i &lt; jsonArray.length(); i++) {
  
                      try {
                      JSONObject jsonObject = jsonArray.getJSONObject(i);
  
  
                      data = jsonObject.getString("user");
                      //items.add(jsonObject.getString("user"));
                      //message+= items.add(jsonObject.getString("message"));
                      message = jsonObject.getString("message");
                      result = data + "\n"+ message;
  
                        items.add(result);
  
                     // Log.d(TAG, "username: \n" + (data.equals("rahul")));
  
  
  
                       //   if (data.equals("rahul"))
                         // {
  
  //                            items.add(result);
  
  
  
  
  
  
  
    //                      }
  
  
  
  
  
                      } catch (JSONException e) {
                          e.printStackTrace();
                      }
  
                  }
  
  
                  adapter.notifyDataSetChanged();
              }
  
          }, new Response.ErrorListener() {
              @Override
              public void onErrorResponse(VolleyError volleyError) {
                  Log.e("Error", "Unable to parse json array");
              }
          });
          // add json array request to the request queue
          requestQueue.add(jsonArrayRequest);
  
  
  
      }
  }
  </code></pre>