Display a number of a php query, using an asynctask

1

I have a query in php that obtains the result and is a real number (1,2,3,4 ...) which are the number of records in the table of BD and I want this number to be shown in Textview. My problem is that how to assign the variable that shows the PHP and assign it to Textview

My Asynctask is next

    public class VerResultadosAsistentes extends AppCompatActivity {
        public static final int CONNECTION_TIMEOUT=10000;
        public static final int READ_TIMEOUT=15000;
        ListView mostrarr;
        String pregrespcomment;
        TextView total;
        private SwipeRefreshLayout swipeContainer;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_ver_resultados_asistentes);
            Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
            setSupportActionBar(toolbar);

            total=(TextView)findViewById(R.id.total_asistidos);

            mostrarr=(ListView)findViewById(R.id.lista);

            swipeContainer = (SwipeRefreshLayout) findViewById(R.id.swipeContainer);

            swipeContainer.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
                @Override
                public void onRefresh() {
                    new AsyncRetrieve().execute();
                    swipeContainer.setRefreshing(false);

                }
            });
            new AsyncRetrieve().execute();

        }
}

        private class AsyncRetrieve2 extends AsyncTask<String, String, String> {
            ProgressDialog pdLoading = new ProgressDialog(VerResultadosAsistentes.this);
            HttpURLConnection conn;
            URL url = null;

            @Override
            protected void onPreExecute() {
                super.onPreExecute();

                pdLoading.setMessage("\tCargando asistentes...");
                pdLoading.setCancelable(false);
                pdLoading.show();

            }


            @Override
            protected String doInBackground(String... params) {
                try {

                    url = new URL("http://bdauditorio.esy.es/ver_asistentes/ver_asistentes.php");

                } catch (MalformedURLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    return e.toString();
                }
                try {


                    conn = (HttpURLConnection) url.openConnection();
                    conn.setReadTimeout(READ_TIMEOUT);
                    conn.setConnectTimeout(CONNECTION_TIMEOUT);
                    conn.setRequestMethod("GET");


                    conn.setDoOutput(true);

                } catch (IOException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                    return e1.toString();
                }

                try {

                    int response_code = conn.getResponseCode();


                    if (response_code == HttpURLConnection.HTTP_OK) {


                        InputStream input = conn.getInputStream();
                        BufferedReader reader = new BufferedReader(new InputStreamReader(input));
                        StringBuilder result = new StringBuilder();
                        String line;

                        while ((line = reader.readLine()) != null) {
                            result.append(line);
                        }


                        return (result.toString());

                    } else {

                        return ("unsuccessful");
                    }

                } catch (IOException e) {
                    e.printStackTrace();
                    return "exception";
                } finally {
                    conn.disconnect();
                }


            }


            @Override
            protected void onPostExecute(String result) {

                pdLoading.dismiss();
                if (result.equalsIgnoreCase("exception") || result.equalsIgnoreCase("unsuccessful")) {
                    final AlertDialog.Builder alertaDeError = new AlertDialog.Builder(VerResultadosAsistentes.this);
                    //  alertaDeError.setTitle("Error");
                    alertaDeError.setMessage("Ups, no se han podido cargar las respuestas. Intentelo de nuevo.");
                    alertaDeError.setPositiveButton("Aceptar", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                        }
                    });
                    alertaDeError.create();
                    alertaDeError.show();
                } else {
                    //procedimiento para el textview 
                }
            }


        }
    }
    
asked by Ashley G. 06.02.2017 в 00:03
source

0 answers