获取变量值OnpostExecute(Async)

时间:2016-05-06 22:44:19

标签: java android json variables asynchronous

我需要获取我的OnpostExecute中的id的值。

查看包含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();

所以我尝试将我的类更改为删除调用String值&#34; id&#34;,但我无论如何都不能使用此值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 个答案:

答案 0 :(得分:0)

我不明白你在做什么,但你可以用这种方式做到。您必须通过删除类构造函数从另一个活动获取一些变量和类。

weights=