怎么在进度条Dialog结束后显示toast

qq_37001599 2017-10-28 03:03:45
想实现这效果,但是我不知道把这Toast怎么处理才能在我的进度条对话框结束后显示出来。

public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button but1=(Button)findViewById(R.id.but1);
but1.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
AlertDialog.Builder myDialog=new AlertDialog.Builder(MainActivity.this);
final View dialogView=LayoutInflater.from(MainActivity.this).inflate(R.layout.res,null);
myDialog.setTitle("登录界面");
myDialog.setView(dialogView);
myDialog.setPositiveButton("确定", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
final int Max_PROGRESS=5;
final ProgressDialog waitingDialog=new ProgressDialog(MainActivity.this);
waitingDialog.setMessage("登录中....");
waitingDialog.setCancelable(false);
waitingDialog.setIndeterminate(true);
waitingDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
waitingDialog.show();
new Thread(new Runnable(){
@Override
public void run(){
int progress=0;
while(progress<Max_PROGRESS){
try{
Thread.sleep(1000);
progress++;
waitingDialog.incrementProgressBy(progress);
}catch(InterruptedException e){
e.printStackTrace();
}
waitingDialog.cancel();
}
}
}).start();

}
});
myDialog.show();
}

});
}
...全文
277 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuankangsan 2017-11-01
  • 打赏
  • 举报
回复
new Thread(new Runnable(){ @Override public void run(){ int progress=0; while(progress<Max_PROGRESS){ try{ Thread.sleep(1000); progress++; waitingDialog.incrementProgressBy(progress); }catch(InterruptedException e){ e.printStackTrace(); }
moonFY 2017-10-30
  • 打赏
  • 举报
回复
如果在同一个页面 有网络请求 就在请求回调中 toast 没有就判断进度条是否到了100 是 就toast 如果不是同一个界面 就无法toast了 在当前页面toast 后 进入下一页面 就会 消失, 只能在下一个页面进行toast 。
江三木洛 2017-10-30
  • 打赏
  • 举报
回复
waitingDialog.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { Toast.makeText(MainActivity.this,"onDismiss",Toast.LENGTH_SHORT).show(); } });

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧