title: How to retrieve particular user data from MySQL database and display in listview?
body: <p>I am developing Android app that is canteen automation system. I wanted to display the all order which are placed by user and that I have stored in order table. Now problem is that I have no idea how to retrieve data from MySQL and display in list view for that particular user order history data.</p>
  
  <p>This is for my final year project.</p>
  
  <pre><code>import android.app.ProgressDialog;
  import android.content.SharedPreferences;
  import android.os.Bundle;
  import android.support.v7.app.AppCompatActivity;
  import android.view.View;
  import android.widget.ArrayAdapter;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.ListView;
  import android.widget.TextView;
  import android.widget.Toast;
  
  import com.android.volley.RequestQueue;
  import com.android.volley.Response;
  import com.android.volley.VolleyError;
  import com.android.volley.toolbox.StringRequest;
  import com.android.volley.toolbox.Volley;
  
  import org.json.JSONArray;
  import org.json.JSONException;
  import org.json.JSONObject;
  
  import java.util.ArrayList;
  import java.util.List;
  import java.util.Map;
  
  
  public class OrderScreen extends AppCompatActivity implements View.OnClickListener {
  
      private EditText editTextId;
      private Button buttonGet;
      private TextView textViewResult;
      private ProgressDialog loading;
      String result = null;
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_order_screen);
          SharedPreferences sp = getSharedPreferences("login", 0);
          String user_id = sp.getString("userid", null);
          editTextId = (EditText) findViewById(R.id.editTextId);
          editTextId.setText(user_id);
          buttonGet = (Button) findViewById(R.id.buttonGet);
  
  
          buttonGet.setOnClickListener(this);
  
      }
  
      List&lt;Map&lt;String, String&gt;&gt; countryList = new ArrayList&lt;Map&lt;String, String&gt;&gt;();
  
      private void getData() {
          String id = editTextId.getText().toString().trim();
          if (id.equals("")) {
              Toast.makeText(this, "Please enter an id", Toast.LENGTH_LONG).show();
              return;
          }
          loading = ProgressDialog.show(this, "Please wait...", "Fetching...", false, false);
  
          String url = Config.DATA_URL + editTextId.getText().toString().trim();
  
          StringRequest stringRequest = new StringRequest(url, new Response.Listener&lt;String&gt;() {
              @Override
              public void onResponse(String response) {
                  loading.dismiss();
                  showJSON(response);
              }
          },
                  new Response.ErrorListener() {
                      @Override
                      public void onErrorResponse(VolleyError error) {
                          Toast.makeText(OrderScreen.this, error.getMessage().toString(), Toast.LENGTH_LONG).show();
                      }
                  });
  
          RequestQueue requestQueue = Volley.newRequestQueue(this);
          requestQueue.add(stringRequest);
      }
  
      private void showJSON(String response) {
          String name = "";
  
  
          try {
              JSONObject jsonObject = new JSONObject(response);
              JSONArray result = jsonObject.getJSONArray(Config.JSON_ARRAY);
  
              for(int i=0; i&lt;result.length(); i++) {
                  JSONObject collegeData = result.getJSONObject(i);
                  String[] values = new String[]{collegeData.getString(Config.KEY_NAME)};
  
                  // address = collegeData.getString(Config.KEY_ADDRESS);
                  //   vc = collegeData.getString(Config.KEY_VC);
  
  
                  ListView listView = (ListView) findViewById(R.id.listview);
  
                  ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this,
                          android.R.layout.simple_list_item_1, android.R.id.text1, values);
                  listView.setAdapter(adapter);
              }
          }
  
  
  
          catch (JSONException e) {
              e.printStackTrace();
  
          }
  
      }
  
          @Override
          public void onClick(View v) {
              getData();
          }
      }
  </code></pre>