2016-06-21 189 views
-1

在下拉列表中點擊時,我有一個按鈕,點擊時顯示的下拉列表中,我有2個菜單,反饋菜單和註銷菜單警告對話框顯示按鈕

mRightButton.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      PopupMenu popup = new PopupMenu(MapsActivity.this, mRightButton); 
      popup.getMenuInflater() 
        .inflate(R.menu.nav_drawer, popup.getMenu()); 

      popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { 
       public boolean onMenuItemClick(MenuItem item) { 
        int id = item.getItemId(); 
        if (id == R.id.action_feedback) { 
         AlertDialog.Builder alertDialog = new AlertDialog.Builder(); 
         alertDialog.setTitle("Feedback"); 
         alertDialog.setMessage("Beri kritik dan saran untuk aplikasi ini ?"); 
         alertDialog.setIcon(R.drawable.ic_near_me_black_48dp); 

         alertDialog.setPositiveButton("YA", new DialogInterface.OnClickListener() { 
          public void onClick(DialogInterface dialog, int which) { 
           Intent emailIntent = new Intent(Intent.ACTION_SEND); 
           emailIntent.putExtra(Intent.EXTRA_EMAIL,new String[] { "[email protected]" }); 
           emailIntent.setType("message/rfc822"); 
           startActivity(Intent.createChooser(emailIntent, "Send email...")); 
          } 
         }); 

         alertDialog.setNegativeButton("TIDAK", new DialogInterface.OnClickListener() { 
          public void onClick(DialogInterface dialog, int which) { 
           Toast.makeText(getApplicationContext(), "Bantu kami untuk meningkatkan kinerja dan performa aplikasi ini dengan memberi feedback", 
             Toast.LENGTH_LONG).show(); 
          } 
         }); 
         alertDialog.show(); 

我進入「這個「在AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);但它是錯誤的,我應該輸入什麼代碼?

回答

0

而不是this,添加YourActivity.this

AlertDialog.Builder alertDialog = new AlertDialog.Builder(YourActivity.this); 
+0

哦好吧它的作品,謝謝! –