2012-04-20 155 views
0

我試圖彈出一個自定義對話框,當我點擊一個按鈕,但它不會彈出。我的應用程序基本上是一個日曆,我打算使用sqlite在日曆中使用對話框添加/保留約會和東西到日期,這是指定約會細節的地方。自定義對話框不顯示 - Android

我使用這個代碼如下:

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); 
    } 

我在做什麼錯?

回答

3

爲您的對話調用show()方法。

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

感謝工作嘿嘿,但我得到了一個運行時異常,所以在我的代碼中必須有錯誤 – a7omiton 2012-04-20 09:14:46

+0

@ AZ1而'RuntimeException'說...? – Luksprog 2012-04-20 09:16:05

+0

04-20 09:16:03.286:E/AndroidRuntime(1188):android.view.WindowManager $ BadTokenException:無法添加窗口 - 標記null不適用於應用程序 – a7omiton 2012-04-20 09:17:57