从对话框转到另一个活动

时间:2017-08-20 12:18:23

标签: android

我想在确认退出警报框后进入我的登录活动,但它对我不起作用。任何人都可以帮我解决一下吗?

这是 navigation.java

final Dialog mydialog = new Dialog(this);
mydialog.setTitle("Confirm Logout");
mydialog.setContentView(R.layout.logoutdialog);
Button yesoption = (Button) findViewById(R.id.yes);
Button nooption = (Button) findViewById(R.id.no);
yesoption.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {

        LoginManager.getInstance().logOut();
        Intent login = new Intent(navigation.this, signin.class);
        startActivity(login);
        finish();
    }

});
nooption.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        mydialog.dismiss();

    }
});

mydialog.show();
}

1 个答案:

答案 0 :(得分:1)

您需要使用该对话框从自定义布局中获取按钮视图的实例。试试吧。

    final Dialog mydialog = new Dialog(this);
    mydialog.setTitle("Confirm Logout");
    mydialog.setContentView(R.layout.logoutdialog);
    Button yesoption = (Button)mydialog.findViewById(R.id.yes);
    Button nooption = (Button)mydialog.findViewById(R.id.no);

    yesoption.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            LoginManager.getInstance().logOut();
            Intent login = new Intent(navigation.this , signin.class);
            login.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(login);
            finish();
        }

    });

    nooption.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mydialog.dismiss();

        }
    });

    mydialog.show();
}