gpt4 book ai didi

android - 取消或关闭 android 警报对话框

转载 作者:行者123 更新时间:2023-11-29 14:27:56 26 4
gpt4 key购买 nike

我正在使用以下函数在我的 android View 中创建/显示加载

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();

}

我将此函数称为异步任务

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);
}

}

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

现在我需要在网络服务请求完成后删除加载

所以我在 onPostExecute 中写了 builder.cancel(); 但它不起作用

有什么想法吗?提前致谢

最佳答案

代替普通的对话框,您可以使用进度对话框,如下所示:

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();
}

关于android - 取消或关闭 android 警报对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16607676/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com