取消或驳回的Andr​​oid警报对话 [英] Cancel or dismiss android alert dialogue

查看:118
本文介绍了取消或驳回的Andr​​oid警报对话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建/显示用下面的函数在我的Andr​​oid视图加载

I am creating / showing a loading in my android view with the following function

public void showDialogue(String Message, String Title){
    builder = new AlertDialog.Builder(this);
    progress = new ProgressBar(this);
    builder.setMessage(Message);
    builder.setView(progress);
    builder.create().show();

}

我调用这个函数作为ASYN tasklike

I am calling this function as an asyn tasklike

private class SetParm extends AsyncTask<String, Integer, String> {

        Integer myid;
        Integer myFlag;
        Integer removeId;
        @Override
        protected String doInBackground(String... sUrl) {
            try {

                SharedPreferences mPrefs = getSharedPreferences("prefs",0);    
                String restoredText = mPrefs.getString("access_token", ""); 
                String path = "http://www.sitename.com/app/setFlag.php";

                HttpClient client = new DefaultHttpClient();
                HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000); // Timeout

                HttpResponse response;
                JSONObject json = new JSONObject();
                try {
                    HttpPost post = new HttpPost(path);
                    json.put("access_token", restoredText);
                    json.put("id", myid);
                    json.put("flag", myFlag);

                    Log.i("jason Object", json.toString());
                    post.setHeader("json", json.toString());
                    StringEntity se = new StringEntity(json.toString());
                    se.setContentEncoding((Header) new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
                    post.setEntity(se);
                    response = client.execute(post);
                    /* Checking response */
                    if (response != null) {
                        InputStream in = response.getEntity().getContent(); 

                        String a = convertStreamToString(in);

                        JSONObject jsono = stringToJsonobj(a);
                        Log.v("TAGG",a);
                        String passedStringValue = jsono.getString("result");


                        if(passedStringValue.equals("1")){
                            flags=1;
                            //Log.v("TAGG", "Success");
                            SharedPreferences mPrefss = getSharedPreferences("prefs", 0);    
                            SharedPreferences.Editor editor = mPrefss.edit();    
                            editor.putString("access_token", jsono.getString("access_token"));  
                            editor.commit();
                        }
                        else {
                            flags=0;
                            //Log.v("TAGG", "Failed !");
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }


            } catch (Exception e) {
            }
            return null;
        }


        @Override
        protected void onPreExecute() {
            showDialogue("Regestring Your Devide... Please wait.", "Regestring Devide");

            super.onPreExecute();
        }

        @Override
        protected void onProgressUpdate(Integer... progress) {
            super.onProgressUpdate(progress);
        }



        @Override
        protected void onPostExecute(String result) {
            builder.cancel();
            if(flags.equals(1)){
                TableLayout mTable = (TableLayout)findViewById(R.id.tableLayout_1);
                mTable.removeView(findViewById(4500+removeId));
                mTable.removeView(findViewById(6500+removeId));

                int count = mTable.getChildCount();
                if(count<=0){
                    lists="";
                    total="0";
                    LogIN loginUsers1 = new LogIN();
                    loginUsers1.execute("");

                }

            }
            else {
                TextView text = (TextView) findViewById(R.id.status_msg);
                text.setText("Error while processing requests. Please try again.");
            }
            super.onPostExecute(result);
        }

    }

从preExecute调用警报对话()函数。

Calling the alert dialogue from onPreExecute() function.

现在我需要删除的加载,一旦Web服务请求已完成

Now I need to remove the loading once the webservice request has been completed

所以我写了 builder.cancel(); onPostExecute ,但它不工作

So I wrote builder.cancel(); in onPostExecute but its not working

你知道吗?
在此先感谢

Any idea ? Thanks in advance

推荐答案

而不是正常对话框中,可以使用进度对话框,如下所示:

private ProgressDialog progressDialog;

protected void onPreExecute() {
            super.onPreExecute();
            progressDialog= new ProgressDialog(MainActivity.this);
            progressDialog.setMessage("Loading ....");
            progressDialog.setIndeterminate(false);
            progressDialog.setCancelable(true);
            progressDialog.show();
        }

 protected void onPostExecute(String result) {
progressDialog.dismiss();
}

这篇关于取消或驳回的Andr​​oid警报对话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆