单击按钮中的下拉列表时显示警报对话框

Alert Dialog show when clicked on drop down list in Button

我有一个按钮,点击后会显示下拉列表,其中有 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[] { "mrobbyf10@gmail.com" });
                                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);中输入了"this",但出现错误,我应该在其中输入一些代码吗?

而不是 this,添加 YourActivity.this

喜欢

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