Android Studio:每秒添加一个数字 [英] Android Studio: Add number every Second

查看:538
本文介绍了Android Studio:每秒添加一个数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示一个人在特定时间内的收入.为此,我要求进行另一项活动的每月收入(gehalt)和每周工作时间(震惊).然后在第二个活动中,我想通过每秒收入增加每秒TextView showGehaltproSekunde(id = textViewZahl). 我是一个初学者,所以我不知道我在public void run()中到底要写什么.还是还有每秒增加数量的可能性? 我希望有一个人可以帮助我.谢谢!

I want to display the income of a person in a certain time. For this I ask for the income per month (=gehalt) and working hours per week (stunden) in another activity. Then in the second activity I want to increase the TextView showGehaltproSekunde (id = textViewZahl) every second by the income per second. I am a beginner, so I don't know what exactly I have to write in public void run(). Or is there another possibility to increase the number every second? I hope someone can help me. Thank you!

public class SecondScreen extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.secondlayout);
    Timer t, timer;

    Intent getGehalt = getIntent();
    float gehalt = getGehalt.getFloatExtra("Gehalt", 0);

    Intent getStunden = getIntent();
    float stunden = getStunden.getFloatExtra("Stunden", 0);

    double gehaltProSekunde = gehalt/4/stunden/3600;
    double gehaltProSekundeRounded = Math.round(gehaltProSekunde*1000)/1000.0;

    TextView showGehaltProSekunde = (TextView)findViewById(R.id.textViewZahl);
    showGehaltProSekunde.setText(gehaltProSekundeRounded+" €");

    t = new Timer();
    t.scheduleAtFixedRate( new TimerTask() {
        @Override
        public void run() {

        }
    });
}

}

推荐答案

例如分析以下内容:

private Handler mHandler = new Handler();
private boolean wasRun = true;
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
    if(wasRun){               
       //whatever you want to do if run
       //you can add you want to increase variable here
    }
    mHandler.postDelayed(this, 1000);
}
}, 1000); // 1 seconds

这篇关于Android Studio:每秒添加一个数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆