我是新來的android和我想做一個簡單的例子,我點擊一個開始按鈕和另一個活動是打開的,有一個簡單的數字開始在一個和向上計數,但我面臨一個問題,我初始化onCreate方法(在第二個活動)的一些變量後,我應該在哪裏實際啓動while語句來計算和修改文本視圖?後onCreate Android
我寫了這個類:
public class Counter extends Thread{
private TextView tv;
private int i;
public Counter(TextView tv){
this.tv = tv;
}
@Override
public void run() {
while(true){
tv.setText(i);
try {
sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
i++;
}
}
並開始線程在這裏:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game);
counter = new Counter((TextView) findViewById(R.id.textView2));
counter.start();
}
你的代碼在哪裏?你試過了什麼? –
我發佈了一些代碼,我寫了 –
如果我得到你的問題然後在裏面做onResume() –