TestGameActivity 클래스에서 버튼을 만들고 버튼을 눌렀을때
TestView 클래스를 실행시키려고합니다.
지금 소스는 코드에러는 없지만 실행시키고 버튼을 누르면 오류로 종료가 되거든요?
어떻게 해야 버튼을눌렀을때 TestView클래스를 불러올수있을까요?
=======================================================
=======================================================
package com.example.testgame;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
public class TestGameActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(new TestView(this));
//setContentView(R.layout.main);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT);
LinearLayout baseLayout = new LinearLayout(this);
baseLayout.setOrientation(LinearLayout.VERTICAL);
setContentView(baseLayout,params);
Button btn = new Button(this);
btn.setText("버튼입니다.");
btn.setBackgroundColor(Color.MAGENTA);
baseLayout.addView(btn);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(TestGameActivity.this, TestView.class);
startActivity(intent);
}
});
}
}
======================================================
======================================================
package com.example.testgame;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.view.View;
public class TestView extends View {
public TestView(Context context) {
super(context);
}
@Override
public void onDraw(Canvas canvas) {
Bitmap _android = BitmapFactory.decodeResource(getResources(),
R.drawable.android);
canvas.drawBitmap(_android, 0, 0, null);
}
}