Return a value from a method (JSON Array)

0

Hello, I have a method that fetches the URL through JSON and wanted to return that value from the method to the mainActivity, to display.

package com.example.fabio.domoticaa;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.EditText;

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.Volley;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class Divi_Dispo extends AppCompatActivity {
String x;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_divi__dispo);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    final String[] count = new String[1];

    final String[] id = new String[1];

    Intent intent = getIntent();
    String value = intent.getStringExtra("divisao");
    final EditText nomediv = (EditText) findViewById(R.id.editText4);
    Count(value);

    nomediv.setText(x);//want set th result of Count(value)


}
public void Count(String value) {
    final String[] count = new String[1];
    // Send data
    try {

        RequestQueue queue = Volley.newRequestQueue(Divi_Dispo.this);

        String url = "http://brunos.000webhostapp.com/teste/obter_id.php?descricao=" + value ;

        JsonArrayRequest jsonRequest = new JsonArrayRequest
                (Request.Method.GET, url, null, new Response.Listener<JSONArray>() {
                    @Override
                    public void onResponse(JSONArray response) {
                        try {
                            JSONObject jObj = new JSONObject(String.valueOf(response.get(0)));
                            count[0] = jObj.getString("COUNT(id)");//quero retornar este valor

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }, new Response.ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError error) {
                        error.printStackTrace();
                    }
                });
        queue.add(jsonRequest);
    } catch (Exception ex) {
    } finally {
    }
}

public interface VolleyCallback {
    void onSuccess(String result);
}

}

    
asked by anonymous 05.01.2017 / 23:00

0 answers