新手学习,求教
用adt创建1.5的工程
然后修改main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.axian.android.test.TestView
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="@string/hello" />
</LinearLayout>
修改如下代码
public class TestActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
public class TestView extends TextView {
public TestView(Context context, AttributeSet attrs) {
super(context, attrs);
setText("counter init=" + counter);
}
private RefreshHandler mRedrawHandler = new RefreshHandler();
class RefreshHandler extends Handler {
@Override
public void handleMessage(Message msg) {
TestView.this.update();
TestView.this.invalidate();
}
public void sleep(long delayMillis) {
this.removeMessages(0);
sendMessageDelayed(obtainMessage(0), delayMillis);
}
};
private long counter = 0;
public void update() {
this.setText("counter=" + counter++);
mRedrawHandler.sleep(100);
}
}
基本就是抄snake例子的呀,为什么定时器不走呀?
------解决方案--------------------
好像LZ没有启动定时器吧。。。。。。。。
------解决方案--------------------
2楼说的没错,调用一下update。。。