Reputation: 23
I have an Activity which is just for displaying the main menu, and then I want to start an Andengine Activity after a Button click.
public class MainMenuActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main_menu_layout);
TextView nadpis = (TextView) findViewById(R.id.nadpis);
Typeface tf = Typeface.createFromAsset(getAssets(), "font/DiamondsPearls.ttf");
nadpis.setTypeface(tf);
Button playGame = (Button)findViewById(R.id.playgame);
playGame.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(this, MonsterTap.class);
startActivity(intent);
}
});
}
}
I see an error referring to the line Intent intent = new Intent(this, MonsterTap.class);
that reads
cannot resolve constructor intent(anonymous android.view.View.OnClickListener, java.lang.class)
What am I doing wrong?
Upvotes: 0
Views: 74
Reputation: 20128
Replace Intent intent = new Intent(this, MonsterTap.class);
with Intent intent = new Intent(MainMenuActivity.this, MonsterTap.class);
to properly pass the intent a Context
.
As you have written it, the this
keyword is referring to the anonymous inner class representing your OnClickListener
.
Upvotes: 1