안드로이드 프로그래밍 예제인데요..이상하게 글씨가 화면에 찍혀나오질 않습니다 좀 봐주세요~
글쓴이: mmx822 / 작성시간: 월, 2013/05/13 - 2:14오후
public class Act1 extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.act1);
}
protected class CanvasView extends View implements Runnable {
private boolean mRun = false;
private int mCount = 0;
public CanvasView(Context context) {
super(context);
}
public Handler mHandler = new Handler() {
public void handleMessage(Message msg) {
if (msg.what == 1) {
invalidate();
}
}
};
@Override
protected void onWindowVisibilityChanged(int visibility) {
super.onWindowVisibilityChanged(visibility); //visibility == true
if (visibility == View.VISIBLE && !mRun) {
mRun = true;
Thread thrd = new Thread(this);
thrd.start();
} else if (mRun) {
mRun = false;
}
}
@Override
public void run() {
while (mRun) {
if (isShown()) //true
mHandler.sendMessage(Message.obtain(mHandler, 1));
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
break;
}
}
}
public void onDraw(Canvas canvas) {
canvas.drawColor(Color.LTGRAY);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(Color.BLACK);
canvas.drawText("Count: " + mCount++, 20, 20, paint);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.act1, menu);
return true;
}
} 이 코드대로면 Count : 0 Count : 1 ..... 이런식으로 10fps의 속도로 화면에 검은색 글씨로 찍혀나와야하는데요..
이상하게 아무런 글씨도... 심지어 캔버스색도 밝은회색으로 나오질 않습니다 ㅜ
그냥 하얀 화면만 계속 떠있네요..어디가 잘못 된걸까요??
Forums:


해결했습니다 ㅜ
캔버스가 보이도록하는 코드
setContentView(new CanvasView(this)); 이걸 안 넣었네요;; ㅈㅅ합니다 ㅜ
댓글 달기