我知道,有人问过类似的问题,我已经浏览了我能找到的所有东西,但我没有找到任何关于这个问题的答案。
这是代码:
protected Dialog onCreateDialog(int id)
{
Dialog dialog = new Dialog(this);
switch(id)
{
case R.layout.database_feed:
dialog.setContentView(R.layout.database_feed);
((Button) dialog.findViewById(R.id.discard_button)).setOnClickListener(
new View.OnClickListener()
{
//@Override
public void onClick(View v)
{
//dialog.cancel();
}
}
);
break;
}
return dialog;
}
我只是想通过单击 R.layout.database_feed 按钮来关闭对话框。但我无法访问 onClick 方法中的对话框。我真的感到很困惑。
我不想使用 AlertDialog 或 DialogBuilder,因为 Dialog 中还有其他一些东西很难在 AlertDialog 或其他东西中实现。此外,我已经知道为对话框创建单独活动的解决方案 - 但实际上我想知道它是如何按照我在这里尝试的方式工作的。此外,我已经尝试使用 DialogInterface.OnClickListener() 但我不能在 setOnClickListener(...) 方法中使用它。
只是取消对话不会那么难……但我不明白。
任何提示/帮助表示赞赏!
谢谢