title: How to get data automatically from MySQL to Android without clicking a button?
body: <p>I want the result of a barcode scan to automatically get data from MySQL without clicking a button again.</p>
  
  <p>This is my code for the button being clicked to get the data from MySQL. How do I get the same data without clicking the button again?</p>
  
  <pre><code>public class EditPerangkat extends AppCompatActivity implements View.OnClickListener {
  
  private EditText editTextNoIT;
  private Button buttonGet;
  private TextView textViewResult;
  
  private ProgressDialog loading;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.editperangkat);
  
      Scan = (Button) findViewById(R.id.buttonScan);
      buttonGet = (Button) findViewById(R.id.buttonGet);
      textViewResult = (TextView) findViewById(R.id.textViewResult);
  
      Scan.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              IntentIntegrator scanIntegrator = new IntentIntegrator(EditPerangkat.this);
              scanIntegrator.initiateScan();
          }
      });
  
      buttonGet.setOnClickListener(this);
  }
  
  private void getData() {
      String it = editTextNoIT.getText().toString().trim();
      if (it.equals("")) {
          Toast.makeText(this, "Please input data", Toast.LENGTH_LONG).show();
          return;
      }
      loading = ProgressDialog.show(this,"Please wait...","Fetching...",false,false);
  
      String url = Config.URL_GET+editTextNoIT.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(EditPerangkat.this,error.getMessage().toString(),Toast.LENGTH_LONG).show();
                  }
              });
  
      RequestQueue requestQueue = Volley.newRequestQueue(this);
      requestQueue.add(stringRequest);
  }
  
  public void showJSON(String response){
      String jenisperangkat="";
      String namaperangkat="";
      String serialnumber= "";
      try {
          JSONObject jsonObject = new JSONObject(response);
          JSONArray result = jsonObject.getJSONArray(Config.JSON_ARRAY);
          JSONObject collegeData = result.getJSONObject(0);
          jenisperangkat = collegeData.getString(Config.KEY_PER_JENISPERANGKAT);
          namaperangkat = collegeData.getString(Config.KEY_PER_NAMAPERANGKAT);
          serialnumber = collegeData.getString(Config.KEY_PER_SERIALNUMBER);
      } catch (JSONException e) {
          e.printStackTrace();
      }
      textViewResult.setText(jenisperangkat + "\n" + namaperangkat + "\n" + serialnumber);
  }
  
  @Override
  public void onClick(View v) {
      getData();
  }
  </code></pre>