Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Studio计数器_Android_Android Studio_Numbers_Counter_Program Counter - Fatal编程技术网

Android Studio计数器

Android Studio计数器,android,android-studio,numbers,counter,program-counter,Android,Android Studio,Numbers,Counter,Program Counter,我在Android Studio中制作的一个小型计数器系统有一个问题,问题是我不知道如何执行计数器加1.5,因为现在每当我按下加号按钮时,它都会执行1,但在下面的脚本geld++中必须是1.5确保在按下按钮时始终添加1,该按钮工作正常,但我不想要1,但我始终想要1.5,但我在任何地方都找不到解决方案。所以我希望有人能帮忙。提前谢谢 package com.example.melkanalysetimer; import androidx.appcompat.app.AppCompatActiv

我在Android Studio中制作的一个小型计数器系统有一个问题,问题是我不知道如何执行计数器加1.5,因为现在每当我按下加号按钮时,它都会执行1,但在下面的脚本
geld++中必须是1.5确保在按下按钮时始终添加1,该按钮工作正常,但我不想要1,但我始终想要1.5,但我在任何地方都找不到解决方案。所以我希望有人能帮忙。提前谢谢

package com.example.melkanalysetimer;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class wit extends AppCompatActivity {
    private TextView countdownText;
    private Button countdownButton;
    private Button krat;
    private Button remove;
    private TextView scoreb;
    private TextView money;
    private TextView reset;

    private CountDownTimer countDownTimer;
    private long timeLeftInMilliseconds = 960000;
    private boolean timerRunning;
    private static final long START_TIME_IN_MILLIS = 960000;

    int score = 0;
    int geld = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wit);

        countdownText = findViewById(R.id.countdown_text);
        countdownButton = findViewById(R.id.countdown_button);
        krat = findViewById(R.id.b_add);
        scoreb = findViewById(R.id.tv_score);
        remove = findViewById(R.id.b_remove);
        money = findViewById(R.id.ssgeld);
        reset = findViewById(R.id.button_reset);

        scoreb.setText("Kratjes: "+ score);
        money.setText("Geld: "+ geld);

        krat.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view) {
                score++;
                scoreb.setText("Kratjes: "+ score);
                geld++;
                money.setText("Geld: "+ geld);
            }
        });

        remove.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view) {
                score--;
                scoreb.setText("Kratjes: "+ score);
                geld--;
                money.setText("Geld: "+ geld);
            }
        });

        reset.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                resetTimer();
            }
        });

        countdownButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startStop();
            }
        });

        updateTimer();
    }

    public void startStop() {
        if (timerRunning) {
            stopTimer();
        } else {
            startTimer();
        }
    }

    public void startTimer() {
        countDownTimer = new CountDownTimer(timeLeftInMilliseconds, 1000) {
            @Override
            public void onTick(long l) {
                timeLeftInMilliseconds = l;
                updateTimer();
            }

            @Override
            public void onFinish() {

            }

        }.start();

        countdownButton.setText("PAUZE");
        timerRunning = true;
    }

    public void stopTimer() {
        countDownTimer.cancel();
        countdownButton.setText("START");
        timerRunning = false;
    }

    public void resetTimer() {
        timeLeftInMilliseconds = START_TIME_IN_MILLIS;
        updateTimer();
    }

    public void updateTimer() {
        int minutes = (int) timeLeftInMilliseconds / 60000;
        int seconds = (int) timeLeftInMilliseconds % 60000 / 1000;

        String timeLeftText;

        timeLeftText = "" + minutes;
        timeLeftText += ":";
        if (seconds < 10) timeLeftText += "0";
        timeLeftText += seconds;

        countdownText.setText(timeLeftText);
    }
}
package com.example.melkanalysetimer;
导入androidx.appcompat.app.appcompat活动;
导入android.os.Bundle;
导入android.os.CountDownTimer;
导入android.view.view;
导入android.widget.Button;
导入android.widget.TextView;
公共课堂活动{
私有文本查看倒计时文本;
私人按钮倒计时按钮;
私人按钮克拉特;
私人按钮移除;
私有文本视图记分;
私人短信查看金钱;
私有文本视图重置;
私人倒计时;
私有长TimeleftinMillimes=960000;
私有布尔时间规划;
专用静态最终长启动时间单位为960000;
智力得分=0;
int-geld=0;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_-wit);
countdownText=findViewById(R.id.countdown\u text);
倒计时按钮=findViewById(R.id.倒计时按钮);
krat=findViewById(R.id.b_添加);
scoreb=findViewById(R.id.tv_分数);
移除=findViewById(R.id.b_移除);
money=findviewbyd(R.id.ssgeld);
重置=findViewById(R.id.按钮\重置);
scoreb.setText(“Kratjes:+score”);
money.setText(“Geld:+Geld”);
krat.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图){
分数++;
scoreb.setText(“Kratjes:+score”);
geld++;
money.setText(“Geld:+Geld”);
}
});
remove.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图){
分数--;
scoreb.setText(“Kratjes:+score”);
凝胶--;
money.setText(“Geld:+Geld”);
}
});
reset.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图){
重置计时器();
}
});
countdownButton.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图){
startStop();
}
});
updateTimer();
}
公共void startStop(){
如果(定时){
停止计时器();
}否则{
startTimer();
}
}
公共无效startTimer(){
countDownTimer=新的countDownTimer(TimeleftinMillimes,1000){
@凌驾
公共空白条(长l){
timeleftin毫秒=l;
updateTimer();
}
@凌驾
公共无效onFinish(){
}
}.start();
倒计时按钮;
timerRunning=true;
}
公共无效停止计时器(){
倒计时。取消();
倒计时按钮。设置文本(“开始”);
timerRunning=false;
}
公共无效重置计时器(){
timeleftinmillides=开始时间(单位:毫秒);
updateTimer();
}
公共void updateTimer(){
int分钟=(int)timeleftin毫秒/60000;
int秒=(int)timeleftin毫秒%60000/1000;
字符串timeleftext;
timeleftext=“”+分钟;
timeLeftText+=“:”;
如果(秒数<10)timeLeftText+=“0”;
timeleftext+=秒;
倒计时文本.setText(timeleftext);
}
}

首先,您需要将
Int
更改为
Double
类似

双倍得分=0.00

然后像这样递增/递减

减量

remove.setOnClickListener(new View.OnClickListener(){
    @Override
    public void onClick(View view) {
        //check if score is less then 0 
        if(score > 1.5){
          score = score - 1.5;
        }
        scoreb.setText("Kratjes: "+ score);
        geld--;
        money.setText("Geld: "+ geld);
    }
});
krat.setOnClickListener(new View.OnClickListener(){
        @Override
        public void onClick(View view) {
            score = score + 1.5;
            scoreb.setText("Kratjes: "+ score);
            geld++;
            money.setText("Geld: "+ geld);
        }
    });
增量

remove.setOnClickListener(new View.OnClickListener(){
    @Override
    public void onClick(View view) {
        //check if score is less then 0 
        if(score > 1.5){
          score = score - 1.5;
        }
        scoreb.setText("Kratjes: "+ score);
        geld--;
        money.setText("Geld: "+ geld);
    }
});
krat.setOnClickListener(new View.OnClickListener(){
        @Override
        public void onClick(View view) {
            score = score + 1.5;
            scoreb.setText("Kratjes: "+ score);
            geld++;
            money.setText("Geld: "+ geld);
        }
    });