在对话框类完成活动 [英] Finish activity in dialog class
问题描述
在我的 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 should
finish()`?
推荐答案
您可以如下完成你的活动...
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屋!