0

I need to get the value of an id that is within my OnpostExecute.

Look into my class that contains OnPostExecute:

listaPedido.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> lista, View item, int posicao, long id) {
                    listaPedido.getItemAtPosition(posicao);

                    if (posicao == 0) {
                        AlertDialog.Builder builder = new AlertDialog.Builder(FinalizarPedido.this);//Cria o gerador do AlertDialog
                        builder.setTitle("Item: " + posicao);
                        builder.setMessage("Categoria: " + pedidos_categoria.get(0) + "\nDescrição: " + pedidos_descricao.get(0) + "\nQtd: " + pedidos_qtd.get(0) + "\nUnidade: " + pedidos_unidade.get(0));
                        builder.setNegativeButton("Fechar", null);
                        builder.setPositiveButton("Excluir", new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialogInterface, int i) {
                                        String id = pedidos_id.get(0);
                                        new delete().execute();

                                    }
                        });
                        alerta = builder.create();
                        alerta.show();

So I try to change my class to delete calling the String value "id", but I can not in any way take this value OnPostExecute.

   class delete extends android.os.AsyncTask<String, Integer, String> {
        private StringBuilder sb;
        private ProgressDialog pr;
        private HttpResponse req;
        private InputStream is;

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(FinalizarPedido.this);
            pDialog.setMessage("Excluindo pedido ...");
            pDialog.setIndeterminate(false); pDialog.setCancelable(true);
            pDialog.show();
        }

        @Override
        protected String doInBackground(String... arg0) {

            UserAccessSession userAccess = UserAccessSession.getInstance(FinalizarPedido.this);
            UserSession userSession = userAccess.getUserSession();
            ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
            select objetoselect = new select();
            nameValuePairs.add(new BasicNameValuePair("pedidos_id", objetoselect.id));

            try
            {
                HttpClient httpclient = new DefaultHttpClient();
                HttpPost httppost = new HttpPost("http://guiaserudgeramos.com.br/buysell/pedidos_del.php");
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                HttpResponse response = httpclient.execute(httppost);
                HttpEntity entity = response.getEntity();
                is = entity.getContent();
                InputStreamReader ireader = new InputStreamReader(is);
                BufferedReader bf = new BufferedReader(ireader);
                sb = new StringBuilder();
                String line = null;
                while ((line = bf.readLine()) != null) {
                    sb.append(line);
                }
                Log.e("pass 1", "connection success ");
            }
            catch(Exception e)
            {
                Log.e("Fail 1", e.toString());
                Toast.makeText(getApplicationContext(), "Invalid IP Address",
                        Toast.LENGTH_LONG).show();
            }
            return id;
        }

        @Override
        protected void onPostExecute(String result) {
            super.onPostExecute(result);
            pDialog.dismiss();
            Toast.makeText(getApplicationContext(), "Pedido deletado com sucesso", Toast.LENGTH_LONG).show();
        }

    }


}

1 Answers1

0

I didn't understand what you was doing but you can do it with using this way. You have to get some variables and classes from another Activity by delete class Constructor.

 class delete extends android.os.AsyncTask<String, Integer, String> {
          private StringBuilder sb;
          private ProgressDialog pr;
          private HttpResponse req;
          private InputStream is;
          private Context context;
          public delete(Context _context, ProgressDialog dialog, InputStream input )
          {
               context = _context;
               pr = dialog;
               is = input;             
          }
          @Override
          protected void onPreExecute() {
             super.onPreExecute();
             /*
                 Your operations
             */
          }

          @Override
          protected String doInBackground(String... arg0) {

             /*
                 Your operations
            */
          }

          @Override
          protected void onPostExecute(String result) {
          super.onPostExecute(result);
          /*
             Your operations
          */
        }
   }
}
Hayrullah Cansu
  • 262
  • 5
  • 14
  • Hi, Simply put, I am in need get the value of a variable that is within OnPostExecute which is a method protect void. Any idea how I can retrieve the value of the id of this method? – Ygor Magrii May 06 '16 at 23:21
  • oh, i understand what your need to thing now. i will edit my post – Hayrullah Cansu May 06 '16 at 23:42