在Eclipse中,对于Android编程,我想每隔一(或更多)秒进行一系列计算。我怎么能这样做?
package com.cimorgh.meisam.loan;
import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.TextView;
public class Aghsati extends Activity {
EditText edt_1;
TextView txt_1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.aghsati);
edt_1 = (EditText) findViewById(R.id.edt_1);
txt_1 = (TextView) findViewById(R.id.txt_1);
// Tasks that I want to do every one second:
double a = Double.parseDouble(edt_1.getText().toString());
txt_1.setText("" + Math.round(a));
}
}
任何人都可以帮忙吗?
答案 0 :(得分:-1)
public void mycalculations()
{
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
// your calulation
mycalculations();
}, 1000); // 1000=1 second
}
在onCreate活动方法中调用mycalculations()