How can I enter the Intent command inside the dialog? I cannot enter the setonclicklistener command inside another setonclicklistener.

Thank you for helping me

i make a dialog after click on button in Mainactivity i want use Intent command for go to other activity by clicking on button in dialog for example : go to other activity

Intent i= new Intent(Mainactivity.this , Musicactivity.class);

startActivity(i);

2 Answers

0
majid jafari On

i maked a dialog after click on button in Mainactivity

i want use Intent command for go to other activity by clicking on button in dialog

for example go to other activity:

Intent i= new Intent(Mainactivity.this , Musicactivity.class);
startActivity(i);
0
majid jafari On

This is my code

This code displays a stop error

        contactus = findViewById(R.id.contactus);

       contactus.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final Dialog dialog = new Dialog(MainActivity.this);
            dialog.setContentView(R.layout.dialog1);
            dialog.setTitle("wellcome");

            btnd1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Uri uri = Uri.parse("https://www.instagram.com/mahdijafarilahijan/");
                    Intent i= new Intent(Intent.ACTION_VIEW,uri);
                    i.setPackage("com.instagram.android");
                    try {
                        startActivity(i);
                    } catch (ActivityNotFoundException e) {
                        startActivity(new Intent(Intent.ACTION_VIEW,
                                Uri.parse("https://www.instagram.com/mahdijafarilahijan/")));
                    }
                }
            });


            dialog.show();
        }
    });