Android中加载另一个Activity时无法显示进度条
这可能是一个简单的问题,但我是初学者,我需要你的建议。 我有两个活动 A1 和 A2。当我单击 A1 屏幕上的图像时,我必须显示进度条,直到出现 A2 屏幕(A2 活动有大量任务要做)。我尝试过
image.setOnClickListener(new ImageView.OnClickListener() {
public void onClick(View v)
{
myProgressDialog = ProgressDialog.show(A1.this,
"Please wait...", "Loading...", true);
new Thread() {
public void run() {
try{
Intent i = new Intent(A1.this,.A2.class);
startActivity(i);
} catch (Exception e) { }
// Dismiss the Dialog
myProgressDialog.dismiss();
}
}.start();
}
});
这无法显示进度条。我知道我我犯了一个错误,但我不明白
This may be a simple question but i am a beginner ,i need your suggestion on this.
i have two Activities A1 and A2 .When i click the image on A1 screen i have to display progress bar until A2 screen appears(A2 activity has huge task to do).I tried
image.setOnClickListener(new ImageView.OnClickListener() {
public void onClick(View v)
{
myProgressDialog = ProgressDialog.show(A1.this,
"Please wait...", "Loading...", true);
new Thread() {
public void run() {
try{
Intent i = new Intent(A1.this,.A2.class);
startActivity(i);
} catch (Exception e) { }
// Dismiss the Dialog
myProgressDialog.dismiss();
}
}.start();
}
});
This couldn't display progress bar .I know that i am making a mistake but i couldn't figure out
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最好的办法是在 A2 活动中显示进度对话框。一旦启动一个活动,前一个活动就会进入后台,因此进度对话框无论如何都不会显示。
Your best bet is to show the progress dialog in the A2 activity. Once you start an Activity, the previous activity goes into the background, so the progress dialog wouldn't display anyway.
首先,需要在单独的线程上调用进度对话框。使用 AsyncTask<>显示对话框并同时在后台执行一些操作。示例代码可能是这样的
First of all , the progress dialog needs to be called on a separate thread . Use the AsyncTask<> to display the dialog and at the same time perform some operation in the background . A sample code might be something like this