自己新建了一个对话框,在响应确定键里边有一个比较耗时的操作,现在想在执行操作的时候加一个圆形进度条的对话框,让用户知道不是程序死掉了,还在正常运行,自己尝试了一下,加的圆形进度条的对话框一直没有显示啊
AlertDialog.Builder dialog = new AlertDialog.Builder(MyActivity.this);
dialog.setTitle(file.getName());
dialog.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Dialog dlg = new Dialog(MyActivity.this);
dlg.setTitle("请等待");
dlg.setContentView(R.layout.pro_dialog);// 这里添加的是一个包含圆形进度条的对话框
dlg.show();
------这里就是添加的那个耗时程序-----
dlg.dismiss();
});
dialog.create().show();
AlertDialog.Builder dialog = new AlertDialog.Builder(MyActivity.this);
dialog.setTitle(file.getName());
dialog.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Dialog dlg = new Dialog(MyActivity.this);
dlg.setTitle("请等待");
dlg.setContentView(R.layout.pro_dialog);// 这里添加的是一个包含圆形进度条的对话框
dlg.show();
------这里就是添加的那个耗时程序-----
dlg.dismiss();
});
dialog.create().show();
解决方案 »
- 安卓程序导入时出现错误:Project has no project.properties file! Edit the project properties
- 代码怎么实现sd卡中的.apk文件的安装
- 我DDMS 中的菜单让我不小心关了 怎么让他们显示出来啊
- android setPadding()跟setMargins()的区别是什么啊
- Android mp3播放器暂停无法移除歌词更新线程
- 如何 动态更改 Dialog 按钮内容?
- android开发什么东西好呢
- android EditText 移动光标那个箭头
- 学过C,ASP,SQL,想做安卓应用,该看什么书?
- editText隐藏键盘后,再进入键盘不显示
- 如何读取SIM卡上的短信
- 读取当前ImageView的图像
dlg.setTitle("请等待");
dlg.setContentView(R.layout.pro_dialog);// 这里添加的是一个包含圆形进度条的对话框
dlg.show();
------这里就是添加的那个耗时程序-----
dlg.dismiss();
改用AsyncTask方式实现:new testTask().execute();private class testTask extends AsyncTask<String, Void, Boolean>
{
private ProgressDialog progressDialog;
@Override
protected void onPreExecute()
{
progressDialog = new ProgressDialog(MainService.this);
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.setTitle("提示");
progressDialog.setMessage("正在...");
progressDialog.setIndeterminate(false);
progressDialog.show();
} @Override
protected Boolean doInBackground(String... params) {
// TODO Auto-generated method stub
------这里就是添加的那个耗时程序----- return null;
}
@Override
protected void onPostExecute(Boolean result)
{
if(null!=progressDialog && progressDialog.isShowing())
{
progressDialog.dismiss();
}
}
}
testTask tast = new testTask(mContext, file);
tast.execute();
while(!tast.isCancelled());// 程序就一直死在这儿了,自己添加的isEnd也是一样的long size = tast.getSize();// 自己写的,返回的是耗时函数的结果