簡體   English   中英

無法從OnClickListener啟動Andengine Activity

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM