Robby Firmansyah
Robby Firmansyah

Reputation: 39

Alert Dialog show when clicked on drop down list in Button

I have a button that when clicked show drop down list, in that I have 2 menu, Feedback menu and Log Out menu

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

I enter "this" in AlertDialog.Builder alertDialog = new AlertDialog.Builder(this); but it's error, what should I enter some code in that?

Upvotes: 0

Views: 924

Answers (1)

Renjith
Renjith

Reputation: 5803

Instead of this, add YourActivity.this.

Like

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

Upvotes: 1

Related Questions