CJ_Finger
2016-11-04 09:36
采纳率: 60%
浏览 3.6k
已采纳

关于Android弹出多个对话框的问题

各位大侠好,项目要实现的效果是,先弹出设置密码的对话框,点击确定后,第一个对话框消失,弹出再次确认密码的对话框,可是总是报错

 java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()

下面是两个对话框的代码:

 //设置支付密码
    private void setPayPwd1Dlg(){
        AlertDialog.Builder builder = new AlertDialog.Builder(TransferActivity.this);
        builder.setTitle("请设置支付密码");
        builder.setView(et_payp);
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                dialog.dismiss();
                setPayPwd2Dlg(et_payp.getText().toString());
            }
        });
        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                dialog.dismiss();
            }
        });
        builder.show();
    }
    //再次确认支付密码
    private void setPayPwd2Dlg(String paypwd){
        final String paypwd1 = paypwd;
        AlertDialog.Builder builder = new AlertDialog.Builder(TransferActivity.this);
        builder.setTitle("请再次输入支付密码");
        builder.setView(et_payp);
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                dialog.dismiss();
                if(et_payp.getText().toString().equals(paypwd1)){
                    new Thread(setPayPwd).start();
                }else {
                    Toast.makeText(getApplicationContext(), "两次密码不一致", Toast.LENGTH_SHORT).show();
                }
            }
        });
        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                dialog.dismiss();
            }
        });
        builder.show();
    }

请问这个问题要怎么解决?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • RoidCoder 2016-11-04 15:09
    已采纳

    Can't create handler inside thread that has not called Looper.prepare()

    在子线程中创建Handler之前,必须调用Looper.prepare()来创建Loopger对象

    主线程中默认是有一个Looper对象的,所以可以直接创建Handler

    点赞 评论
  • CWhy7 2016-11-04 10:16

    dialog.dismiss();
    Looper.prepare()
    setPayPwd2Dlg(et_payp.getText().toString());

    这样试下吧,这个是缺少loop,也可能是线程问题

    点赞 评论

相关推荐 更多相似问题