2011-05-24 27 views
0

嗨我一直在添加一個複選框到對話框窗口有一些困難。該對話框包含說明,我不希望它每次都顯示。我希望它在用戶選中複選框並單擊確定時停止顯示。一段時間的代碼,我得到一個強制關閉,因爲點擊監聽器的複選框,但不知道如何實現它。 在此先感謝您的幫助。添加複選框到對話框的問題

下面的代碼

 private void dialog(){ 
    final SharedPreferences settings = this.getSharedPreferences("MyApp",0); 
    boolean stillrun=settings.getBoolean("stillrun",true); 

    if (stillrun) {   
     final Dialog dialog = new Dialog(Zoom.this); 
     dialog.setContentView(R.layout.info);  
     dialog.setTitle("Using the zoom function"); 
     dialog.setCancelable(true); 
     TextView text = (TextView) dialog.findViewById(R.id.text);  
     text.setText(R.string.zoomtext);   
     Button button = (Button) dialog.findViewById(R.id.buttonClose); 


     button.setOnClickListener(new OnClickListener() { 
     public void onClick(View v) {        
     dialog.cancel(); 
      } 
     }); 


     CheckBox checkbox = (CheckBox) findViewById(R.id.checkBox1); 
     checkbox.setOnClickListener(new OnClickListener() { 
     public void onClick(View v) { 

      if (((CheckBox) v).isChecked()) { 
      SharedPreferences.Editor e = settings.edit(); 
       e.putBoolean("stillrun",false); 
       e.commit(); 
      } 
     } 
    }); 

    dialog.show(); 



}  

回答

0

您閱讀「stillrun」的屬性,並寫入屬性「firstrun」 - 這是你想要的嗎?

+0

非常感謝你的發現,確實有任何想法我可以如何解決部隊關閉問題。它與點擊監聽器上的複選框有關,但我不知道如何在對話框中實現它。再次感謝! – scotty65 2011-05-24 11:17:57