private ProgressDialog pdialog;
private Handler proHandler;
private static int MAX_PROGRESS = 100;
private int progress;
showProgressDialog(ProgressDialog.STYLE_HORIZONTAL);
showProgressDialog(ProgressDialog.STYLE_SPINNER);
private void showProgressDialog(int style)
{
pdialog = new ProgressDialog(context);
pdialog.setIcon(R.drawable.icon);
pdialog.setTitle(“数据处理中…”);
pdialog.setMessage(“请稍后…”);
pdialog.setProgressStyle(style);
pdialog.setMax(MAX_PROGRESS);
pdialog.setButton(“暂停”, new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
proHandler.removeMessages(1);
}
});
pdialog.setButton(“取消”, new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
proHandler.removeMessages(1);
progress = 0;
pdialog.setProgress(0);
}
});
pdialog.show();
proHandler = new Handler()
{
public void handleMessage(Message msg)
{
super.handleMessage(msg);
if (progress >= MAX_PROGRESS)
{
progress = 0;
pdialog.dismiss();
}
else
{
progress++;
pdialog.incrementProgressBy(1);
proHandler.sendEmptyMessageDelayed(1, 50 + new Random().nextInt(500));
}
};
};
progress = (progress > 0) ? progress : 0;
pdialog.setProgress(progress);
proHandler.sendEmptyMessage(1);
}今天的文章ProgressDialog进度条显示分享到此就结束了,感谢您的阅读,如果确实帮到您,您可以动动手指转发给其他人。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/33647.html