gpt4 book ai didi

android - 为什么我看不到使用此 Activity 的 ProgressDialog?

转载 作者:搜寻专家 更新时间:2023-11-01 08:12:18 26 4
gpt4 key购买 nike

我无法让我的 ProgressDialog 显示出来,我不确定为什么?

代码:

public class Activity001 extends Activity implements OnClickListener 
{
public void onClick(View view)
{
ProgressDialog progressDialog = ProgressDialog.show(Activity001.this, "", "wait ", true, false);

// Sending some files to server .. takes time .. - (method that take 1-2 minutes )

progressDialog.dismiss();

}
}

谁能帮帮我?

最佳答案

试试这个,

在您的 onCreate() 中执行此操作

       Handler handler;
handler = new Handler() {
@Override
public void handleMessage(Message msg) {
if (msg.what == 0) {
Pdialog.dismiss();


}
};

现在使用线程将文件上传到服务器。修改这段代码,

public class Activity001 extends Activity implements OnClickListener 
{
public void onClick(View view)
{
ProgressDialog progressDialog = ProgressDialog.show(Activity001.this, "", "wait ", true, false);
Thread ProgressThread = new Thread() {
@Override
public void run() {
try {
// Sending some files to server .. take time .. - (method that take 1-2 minuts )



} catch(InterruptedException e) {
// do nothing
} finally {

handler.sendEmptyMessage(0);
}
}
};

ProgressThread.start();


}

}

编辑

进度对话框是一个轻量级对象。它不会优先于主线程中发生的其他任务。例如,当您在主线程中调用一个进度对话框的 show() 后跟一个 http 进程或类似的东西时,它不会让轻量级的 prgoress 对话框获得优先权。所以很明显它只会出现在 http 进程的末尾。

关于android - 为什么我看不到使用此 Activity 的 ProgressDialog?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8712295/

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