Android的问题,进度对话框 [英] android problem with progress dialog
问题描述
在我的应用程序I M试图获取来自服务器的数据,并在数据库中存储。
当这样做当时progressdialog所有这些工作,我想应该显示,如果成功读取数据然后对话框应该关闭一些alertDialog应该显示消息成功获取数据。如果任何N / W有问题,那么就应该表现出不同的味精说:有n个问题/ W。
In my app i m trying to fetch data from server and storing in database. When it is doing all these work i want at that time progressdialog should show, if successfully data fetches then dialog should close and some alertDialog should show for msg "successfully data fetched". and if any n/w problem there, then it should show different msg that "problem with n/w".
对于我这样做像下面,
public void onClick(View arg0) {
myProgressDialog = ProgressDialog.show(
getParent(), "Please wait...",
"Doing upgrade...", true);
new Thread() {
public void run() {
try {
upgradeAll();//function where data fetched from server
sleep(5000);
} catch (Exception e) {
}
// Dismiss the Dialog
myProgressDialog.dismiss();
Toast.makeText(UpgradeAllTableData.this, "Due to some internal problem \n" +
"it couldnot update..", Toast.LENGTH_LONG).show();
}
}.start();
}
AsyncTask的code,
AsyncTask code,
private class UpgradeTask extends AsyncTask<Context, Void, Void> {
private ProgressDialog Dialog = new ProgressDialog(UpgradeAllTableData.this);
@Override
protected void onPreExecute() {
System.out.println("In onPreExecute ");
Dialog.setTitle("Loading");
Dialog.setMessage("Please wait for few seconds...");
Dialog.show();
}
@Override
protected Void doInBackground(Context... params) {
System.out.println("In doInBackground ");
upgradeAll();
System.out.println("In doInBackground after fetching");
return null;
}
@Override
protected void onPostExecute(Void unused) {
System.out.println("In onPostExecute ");
Dialog.dismiss();
Toast.makeText(UpgradeAllTableData.this, "Problem with internet" , Toast.LENGTH_SHORT).show();
alertboxNeutral("Warning", "Problem with Internet Connection", "Okay","Try again");
}
}
问题是吐司没有显示。为什么?
Problem is Toast is not showing. why?
我的问题是条件,在这里给它,这样,如果有n任何问题/ W则表现出一定的味精和成功然后显示另一个味精。
My question is which condition and where to give so that if any problem with n/w then it show some msg and success then show another msg.
在哪里我应该写code是什么?
给我一些建议。
Where i should write code for that? Give me some suggestion.
感谢您
推荐答案
你在做什么是完全错误的。 UI线程处理所有用户界面的变化,但在这里,你是在UI线程创建ProgressDialog和其他线程贬..一个解决方案是使用的AsyncTask的 http://developer.android.com/reference/android/os/AsyncTask.html
What you are doing is totally wrong. UI thread handles all UI changes, but here you are creating ProgressDialog in UI thread and dismissing it in some Other Thread.. A solution is make use of AsyncTask http://developer.android.com/reference/android/os/AsyncTask.html
这篇关于Android的问题,进度对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!