-6

I am using dialog box. I want that if i click the button, the other activity gets called. But its giving the following error. //The constructor Intent(new DialogInterface.OnClickListener(){}, Class) is undefined

Here's the code

  builder1.setNegativeButton("secondact", new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub
                    Intent i=new Intent(this, FbsampleActivity.class)

                }
            });

6 Answers6

5

start as:

builder1.setNegativeButton("secondact", new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub
                    Intent i=new Intent(Current_Activity.this, FbsampleActivity.class);
                    //or

                    //Intent i=new Intent(getApplicationContext(), FbsampleActivity.class);
                     startactivity(i);
                }
            });

NOTE: Do not use getBaseContext() use getApplicationContext() or Current_Activity.thisenter code here for Starting new Activity

ρяσѕρєя K
  • 130,641
  • 51
  • 193
  • 212
3

If you use the this, the class used in the Intent i=new Intent(this, FbsampleActivity.class) is DialogInterface.OnClickListener class. You need to write YourOuterClass.this (the outer class). Try this:

 builder1.setNegativeButton("secondact", new DialogInterface.OnClickListener() {

      public void onClick(DialogInterface dialog, int which) {
          // TODO Auto-generated method stub
          Intent i=new Intent(YourActivity.this, FbsampleActivity.class)
          startActivity(i);
        }
  });
AMerle
  • 4,328
  • 1
  • 26
  • 43
1
Intent i=new Intent(getApplicationContext(), FbsampleActivity.class)

In your case, "this" refers to the DialogInterface class. You need the context of your Activity.

Carnal
  • 21,284
  • 6
  • 56
  • 73
1
builder1.setNegativeButton("secondact", new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub
                    Intent i=new Intent(YourActivityName.this,FbsampleActivity.class);
                    startActivity(i);
                }
            });
AkashG
  • 7,787
  • 3
  • 27
  • 43
0

use this line below intent.. in your code..

 startactivity(i);
Rahul Baradia
  • 11,749
  • 16
  • 74
  • 121
0

create statically like this..

Intent i=new Intent(YourActivityName.this,ToWhichActivityYouWantToGo.class);
startActivity(i);
Satyam
  • 1,642
  • 3
  • 20
  • 34