[英]Trouble launching Andengine Activity from OnClickListener
我有一個僅用於顯示主菜單的活動,然后單擊按鈕后要啟動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);
}
});
}
}
我看到一條錯誤消息,指向行Intent intent = new Intent(this, MonsterTap.class);
讀
無法解析構造函數意圖(匿名android.view.View.OnClickListener,java.lang.class)
我究竟做錯了什么?
替換Intent intent = new Intent(this, MonsterTap.class);
用Intent intent = new Intent(MainMenuActivity.this, MonsterTap.class);
正確傳遞意圖Context
。
如您所寫, this
關鍵字指的是代表您的OnClickListener
的匿名內部類。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.