[英]Trouble launching Andengine Activity from OnClickListener
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. 我有一个仅用于显示主菜单的活动,然后单击按钮后要启动Andengine活动。
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);
我看到一条错误消息,指向行
Intent intent = new Intent(this, MonsterTap.class);
that reads 读
cannot resolve constructor intent(anonymous android.view.View.OnClickListener, java.lang.class)
无法解析构造函数意图(匿名android.view.View.OnClickListener,java.lang.class)
What am I doing wrong? 我究竟做错了什么?
Replace Intent intent = new Intent(this, MonsterTap.class);
替换
Intent intent = new Intent(this, MonsterTap.class);
with Intent intent = new Intent(MainMenuActivity.this, MonsterTap.class);
用
Intent intent = new Intent(MainMenuActivity.this, MonsterTap.class);
to properly pass the intent a Context
. 正确传递意图
Context
。
As you have written it, the this
keyword is referring to the anonymous inner class representing your OnClickListener
. 如您所写,
this
关键字指的是代表您的OnClickListener
的匿名内部类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.