自定义对话框不显示 - Android

时间:2012-04-20 09:02:33

标签: android dialog customdialog

我正在尝试在单击按钮时弹出自定义对话框,但它根本不会弹出。我的应用程序基本上是一个日历,我将使用sqlite在日历中使用对话框添加/保持约会和填充日期,这是指定约会详细信息的地方。

我正在使用的代码如下:

public void onClick(View v) {
        // TODO Auto-generated method stub
        //long a = calendar.getDate();
        switch(v.getId()){
        case R.id.createButton:
            openCreateAppointmentDialog();
            break;
        }
    }

    private void openCreateAppointmentDialog(){
        Context mContext = getApplicationContext();
        Dialog createAppmntDialog = new Dialog(mContext);

        createAppmntDialog.setContentView(R.layout.create);
        createAppmntDialog.setTitle(R.string.createTitle);

        appointmentTitle = (EditText) createAppmntDialog.findViewById(R.id.titleTextBox);
        appointmentTitle.setText("hello");

        appointmentTime = (EditText) createAppmntDialog.findViewById(R.id.timeTextBox);

        appointmentDetails = (EditText) createAppmntDialog.findViewById(R.id.detailsTextBox);

        saveAppointment = (Button) createAppmntDialog.findViewById(R.id.saveButton);
        saveAppointment.setOnClickListener(this);
    }

我做错了什么?

1 个答案:

答案 0 :(得分:3)

为您的对话框调用show()方法。

createAppmntDialog.show(); //when you want the dialog to appear on the screen