扩展视图和自定义对话框

时间:2011-06-21 21:53:02

标签: android-layout

我正在开发一个游戏,我正在扩展视图并在课堂上执行操作。我需要在游戏中有一个弹出窗口,里面有3个按钮。我已经设法使用自定义对话框进行弹出窗口显示,但是当我按如下方式配置onClick时:

private void popUp() {
    Context mContext = getContext();
    Dialog dialog = new Dialog(mContext);
    dialog.setContentView(R.layout.custom_fullimage_dialog);
    dialog.setTitle("Cheese Market");
    Button one = (Button)findViewById(R.id.firstpack);
    one.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            cheeseLeft = cheeseLeft + 10;
            masterMoveLock = false;
            return;
        }
    });
}

即使在custom_fullimage_dialog布局中定义了它,它也会关闭并提供nullpointerexeption。

有人可以帮我弄清楚如何在这种情况下检测到按钮点击吗?

谢谢。

1 个答案:

答案 0 :(得分:1)

请尝试拨打dialog.findViewById。 您正在为对话框设置contentView,但是通过调用findViewById,您可以在活动的内容视图下查找它。