重写对话框onBack pressed()? [英] Override dialog onBackPressed()?
本文介绍了重写对话框onBack pressed()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将如何重写对话框
的 onBack pressed
关闭对话框以及调用完成()
在活动
它位于?
How would I override a Dialog
's onBackPressed
to close the dialog as well as calling finish()
on the Activity
it is located in?
推荐答案
您可以使用<一个href="http://developer.android.com/reference/android/content/DialogInterface.OnCancelListener.html"><$c$c>setOnCancelListener$c$c>:
dialog.setOnCancelListener(new DialogInterface.OnCancelListener()
{
@Override
public void onCancel(DialogInterface dialog)
{
MyActivity.this.finish();
}
});
您需要完成只有你的活动。对话框会自动关闭。
You need to finish only your activity. Dialog will be dismissed automatically.
这篇关于重写对话框onBack pressed()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文