-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
  • 132,198
  • 53
  • 198
  • 213
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,354
  • 1
  • 28
  • 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,744
  • 6
  • 60
  • 75
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,868
  • 3
  • 28
  • 43
0

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

 startactivity(i);
Rahul Baradia
  • 11,802
  • 17
  • 73
  • 121
0

create statically like this..

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