2017-07-24 116 views
0

我有一個彈出窗口,按下按鈕時會執行。當用戶點擊彈出窗口中的「home」時,我想要一個對話消息彈出詢問用戶是否確定他們要退出。如何在彈出窗口中使用對話框?

這裏是我聲明彈出窗口:

  LayoutInflater inflater = (LayoutInflater) endlessflags.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      layout = inflater.inflate(R.layout.success_menu, (ViewGroup) findViewById(R.id.myPop5)); 

      pwindo4 = new PopupWindow(layout, ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT); 
      pwindo4.setAnimationStyle(R.style.AnimationPopup); 
      pwindo4.showAtLocation(layout, Gravity.TOP | Gravity.CENTER, 0, 0); 

然後我對按鈕也被稱爲在彈出的窗口中onTouchListener。我打電話我創建的對話功能,但是當我做什麼也沒發生,我沒有錯誤或崩潰:

 AlertDialog.Builder myAlert = new AlertDialog.Builder(mainActivity.this); 
     myAlert.setMessage("Would you like to quit?").setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() { 
     @Override 
     public void onClick(DialogInterface dialog, int which) { 
      saveState = true; 
      saveState(); 
      //finish(); 
      dialog.cancel(); 
     } 
     }).setNegativeButton("No", new DialogInterface.OnClickListener() { 
     @Override 
     public void onClick(DialogInterface dialog, int which) { 
      saveState = false; 
      dialog.cancel(); 
      } 
     }); 

我的問題是,爲什麼是它,當我打電話對話事件函數好像沒有什麼改變,以及如何我可以解決這個問題嗎,當我點擊彈出窗口中的一個按鈕時,對話框會顯示出來嗎?

回答

1

你需要顯示對話框:

AlertDialog dialog = myAlert.create(); 
dialog.show(); 
+0

我只是說這兩個線路的它完美地工作!非常感謝您的幫助,我會花更多時間瞭解對話框如何在未來發揮作用! – RW6

相關問題