Java Android:显示progressbar对话框时出现问题?
在我的应用程序中,我试图在函数完成执行所需的时间内显示progressbar,并在函数完成执行后将其关闭 我的代码定义如下:Java Android:显示progressbar对话框时出现问题?,java,android,eclipse,dialog,progress-bar,Java,Android,Eclipse,Dialog,Progress Bar,在我的应用程序中,我试图在函数完成执行所需的时间内显示progressbar,并在函数完成执行后将其关闭 我的代码定义如下: protected Dialog onCreateDialog(int id) { switch (id) { case PROCESS: { ProgressDialog dialog = new ProgressDialog(this); dialog.setTi
protected Dialog onCreateDialog(int id) {
switch (id) {
case PROCESS: {
ProgressDialog dialog = new ProgressDialog(this);
dialog.setTitle("Indeterminate");
dialog.setMessage("Please wait while loading...");
dialog.setIndeterminate(true);
dialog.setCancelable(true);
return dialog;
}
}
return null;
}
showDialog(PROCESS);
doFunction();
dismissDialog(PROCESS);
由于某些原因,processdialog不显示
有人能帮我吗。。。。
有没有其他方法可以做到这一点
谢谢:)由于处理函数需要一些时间,请使用异步任务
new AsyncTask<Void, Void, Void>() {
@Override
protected void onPreExecute()
{
pd = ProgressDialog.show(getApplicationContext(),"", "Sending Image ...", true);
Log.d(TAG, "onPreExecute()");
}
@Override
protected Void doInBackground(Void... params)
{
doFunction();
return null;
}
@Override
protected void onPostExecute(Void res)
{
Log.d(TAG, "onPostExecute()");
pd.dismiss();
}
}.execute();
newasynctask(){
@凌驾
受保护的void onPreExecute()
{
pd=ProgressDialog.show(getApplicationContext(),“”,“正在发送图像…”,true);
Log.d(标记“onPreExecute()”);
}
@凌驾
受保护的Void doInBackground(Void…参数)
{
doFunction();
返回null;
}
@凌驾
受保护的void onPostExecute(void res)
{
Log.d(标记“onPostExecute()”);
pd.解散();
}
}.execute();
其次,将其设置为“不确定”意味着您只能看到一个圆
您应该将样式设置为水平我已经尝试过了,但是我得到了一个类似于….的错误android.view.WindowManager$BadTokenException:无法添加窗口--标记null不适用于应用程序“。。。。你能帮我吗。。。。