在对话框类完成活动 [英] Finish activity in dialog class

查看:209
本文介绍了在对话框类完成活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 MainActivity 我称之为

 myDialog dialog = new myDialog(MainActivity.this);
 dialog.show();

myDialog 是我自己的类,我自定义对话框。
在该对话框是一个按钮。我想了 MainActivity 和对话结束/ dissappears当按钮pressed,因为我开始另一个活动即可。
我怎么能说在 myDialog 类,在 onClickListener ,该 MainActivity应完成()`?

myDialog is my own class where I customize the dialog. In the dialog is a button. I want that the MainActivity and the dialog finishes/dissappears when the button is pressed, because I start another Activity then. How can I say in the myDialog class, in the onClickListener, that the MainActivity shouldfinish()`?

推荐答案

您可以如下完成你的活动...

You can finish your Activity as below...

Intent intent = new Intent(context, YourSecondActivity.class);
context.startActivity(intent);
((Activity) context).finish();

更新:

在你的,你自定义的构造函数对话框类,获得活动场景如下...

In your constructor of you custom dialog class, get the activity context as below...

Context mContext;

public myDialog(Context context) {
    super(context);
    this.mContext = context;
}

然后在的onClick()方法完成如下活动...

then in your onClick() method finish the activity as below...

@Override
public void onClick(View v) {

    Intent menu = new Intent(mContext, menu.class);
    mContext.startActivity(menu);
    ((Activity) mContext).finish();
}

这篇关于在对话框类完成活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆