基本的に、秒カウンターとレベルカウンターを実行しようとしています。10秒ごとに++レベルにしたい。
しかし、それはまだ実装されていません。これまでのところ、表示する秒数を取得しようとしていますが、ランタイム例外とクラッシュが発生しています。
グーグルでは、スレッドから UI を更新しようとしていて、それが許可されていないことが原因であることがわかりました。したがって、asyncTask が必要になると思いますが、単純な小さなプログラムでそれを行う方法がわかりません。助けてください、またはいくつかの代替案を教えてください...
package com.ryan1;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
public class main extends Activity {
int level = 1;
int seconds_running=0;
TextView the_seconds;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
the_seconds = (TextView) findViewById(R.id.textview_seconds);
Thread thread1 = new Thread(){
public void run(){
try {
sleep(1000); Log.d("RYAN", " RYAN ");
updated_secs();
} catch (Exception e) {
e.printStackTrace();
Log.d("RYAN", " "+e);
}
}
};
thread1.start();
}
public void updated_secs(){
seconds_running++;
the_seconds.setText(" "+seconds_running);
}
}