Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.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
Java Android:文本框中显示双值_Java_Android_Textview_Double - Fatal编程技术网

Java Android:文本框中显示双值

Java Android:文本框中显示双值,java,android,textview,double,Java,Android,Textview,Double,一个简单的倒计时程序,用于更新双变量的值,然后将值显示在文本框的末尾。我用整数做了这个,它工作得很好,但是当我使用双精度值时,它只是从文本框的末尾消失。发生这种情况有什么原因吗 使用的代码: PSICount = new CountDownTimer(5000,1000) { @Override public void onTick(long millisUntilFinished) { timer2.setText("seconds re

一个简单的倒计时程序,用于更新双变量的值,然后将值显示在文本框的末尾。我用整数做了这个,它工作得很好,但是当我使用双精度值时,它只是从文本框的末尾消失。发生这种情况有什么原因吗

使用的代码:

PSICount = new CountDownTimer(5000,1000) {
        @Override
        public void onTick(long millisUntilFinished) {
            timer2.setText("seconds remaining: " + millisUntilFinished / 1000);
        }

        @Override
        public void onFinish() {
            if(alti >= 33000){
                Random r = new Random();
                double Low = 0.2 ;
                double High = 0.5;
                double randomValue = Low + (High - Low) * r.nextDouble();
                pressure = pressure - randomValue;
                pressureT.setText("Pressure: "+ pressure + " PSI");

            }
            PSICount.start();
        }
    };
    PSICount.start();
这是计时器,如果另一个变量的值高于33000,它每5秒触发一次。一旦该变量达到33000,文本框(其末尾的占位符值为10.0)就不会在末尾显示任何值。我需要做些什么才能在文本视图中使用doubles吗

多谢各位

我的全班同学:

import android.content.pm.ActivityInfo;
import android.graphics.Typeface;
import android.os.CountDownTimer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.util.Random;

public class flight_engineer extends AppCompatActivity {

int fuel = 100;
int alti = 10000;
int speed = 50;
double over_heat = 600;
double pressure = 10.0;

CountDownTimer fuelCount;
CountDownTimer PSICount;
CountDownTimer spike;

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

    //sets screen orientation on created
    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    Typeface typeface = Typeface.createFromAsset(getAssets(), "Stencil WW.ttf");

    final TextView fuelT = (TextView) findViewById(R.id.fuelText);
    final TextView pressureT = (TextView) findViewById(R.id.presText);
    final TextView altitudeT = (TextView) findViewById(R.id.altText);
    final TextView speedT = (TextView) findViewById(R.id.speedText);
    final TextView over_heatingT = (TextView) findViewById(R.id.heatText);
    final TextView info = (TextView) findViewById(R.id.infoText);
    final TextView timer = (TextView) findViewById(R.id.timer);
    final TextView timer2 = (TextView) findViewById(R.id.timer2);

    fuelT.setTypeface (typeface);
    pressureT.setTypeface (typeface);
    altitudeT.setTypeface (typeface);
    speedT.setTypeface (typeface);
    over_heatingT.setTypeface (typeface);
    info.setTypeface(typeface);

    fuelT.setText("Fuel: "+fuel);
    pressureT.setText("Pressure: "+ pressure+ " PSI");
    altitudeT.setText("Altitude: "+alti+" ft");
    speedT.setText("Speed: "+speed+" MPH");
    over_heatingT.setText("System Heat: "+over_heat+" °C");

    Button speedPlus = (Button) findViewById(R.id.speedPlus);

    speedPlus.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

        }
    });


    fuelCount = new CountDownTimer(2000,1000) {
        @Override
        public void onTick(long millisUntilFinished) {
            timer.setText("seconds remaining: " + millisUntilFinished / 1000);
        }

        @Override
        public void onFinish() {
            fuelCount.start();
            fuel--;
            fuelT.setText("Fuel: "+fuel);
            over_heat=over_heat + 4;
            fuelT.setText("Fuel: "+fuel);
            over_heatingT.setText("System Heat: "+over_heat+" °C");

            Random r = new Random();
            int Low = 443;
            int High = 872;
            int Result = r.nextInt(High - Low) + Low;
            alti = alti + Result;
            altitudeT.setText("Altitude: "+alti+" ft");



        }
    };
    fuelCount.start();

    PSICount = new CountDownTimer(5000,1000) {
        @Override
        public void onTick(long millisUntilFinished) {
            timer2.setText("seconds remaining: " + millisUntilFinished / 1000);
        }

        @Override
        public void onFinish() {
            if(alti >= 33000){
                Random r = new Random();
                double Low = 0.2 ;
                double High = 0.5;
                double randomValue = Low + (High - Low) * r.nextDouble();
                pressure = pressure - randomValue;
                pressureT.setText("Pressure: "+ pressure + " PSI");

            }
            PSICount.start();
        }
    };
    PSICount.start();

    spike = new CountDownTimer(30000,1000) {
        @Override
        public void onTick(long millisUntilFinished) {

        }

        @Override
        public void onFinish() {

            spike.start();
            over_heat = over_heat + 50;
            over_heatingT.setText("System Heat: "+over_heat+" °C");

            alti = alti + 1000;
            altitudeT.setText("Altitude: "+alti+" ft");

            if(speed < 300 || speed > 300) {
                Random r = new Random();
                int Low = -50;
                int High = 50;
                int Result = r.nextInt(High - Low) + Low;
                speed = speed + Result;
                speedT.setText("Speed: " + speed + " MPH");
            }

        }
    };
    spike.start();

}

}
导入android.content.pm.ActivityInfo;
导入android.graphics.Typeface;
导入android.os.CountDownTimer;
导入android.support.v7.app.AppActivity;
导入android.os.Bundle;
导入android.view.view;
导入android.widget.Button;
导入android.widget.TextView;
导入java.util.Random;
公务舱飞行工程师延长飞行时间{
int燃料=100;
内部高度=10000;
内速度=50;
双过热度=600;
双压=10.0;
倒计时计数;
倒计时计数;
倒计时尖峰;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u flight\u engineer);
//在创建的屏幕上设置屏幕方向
此.setRequestedOrientation(ActivityInfo.SCREEN\u ORIENTATION\u横向);
Typeface-Typeface=Typeface.createFromAsset(getAssets(),“模具WW.ttf”);
最终文本视图fuelT=(文本视图)findViewById(R.id.fuelText);
最终文本视图压力集=(文本视图)findViewById(R.id.presText);
最终文本视图altitudeT=(文本视图)findViewById(R.id.altText);
最终文本视图speedT=(文本视图)findViewById(R.id.speedText);
_heatingT=(TextView)findViewById(R.id.heatText)上的最终文本视图;
最终文本视图信息=(文本视图)findViewById(R.id.infoText);
最终文本视图计时器=(文本视图)findViewById(R.id.timer);
最终TextView timer2=(TextView)findViewById(R.id.timer2);
fuelT.setTypeface(字体);
pressureT.setTypeface(字体);
altitudeT.setTypeface(字体);
speedT.setTypeface(字体);
过度加热设置字体(字体);
信息设置字体(字体);
fuelT.setText(“燃料:+燃料”);
压力设置文本(“压力:+压力+PSI”);
高度设置文字(“高度:+alti+“ft”);
speedT.setText(“速度:“+速度+”英里/小时”);
过热设置文本(“系统热:+过热+”°C”);
按钮speedPlus=(按钮)findViewById(R.id.speedPlus);
setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
}
});
fuelCount=新的倒计时(20001000){
@凌驾
公共void onTick(长毫秒未完成){
timer.setText(“剩余秒数:+millisuntillfinished/1000”);
}
@凌驾
公共无效onFinish(){
fuelCount.start();
燃料--;
fuelT.setText(“燃料:+燃料”);
过热=过热+4;
fuelT.setText(“燃料:+燃料”);
过热设置文本(“系统热:+过热+”°C”);
随机r=新随机();
int低=443;
int高=872;
int结果=r.nextInt(高-低)+低;
高度=高度+结果;
高度设置文字(“高度:+alti+“ft”);
}
};
fuelCount.start();
PSICount=新的倒计时(50001000){
@凌驾
公共void onTick(长毫秒未完成){
timer2.setText(“剩余秒数:+millisuntillfinished/1000”);
}
@凌驾
公共无效onFinish(){
如果(高度>=33000){
随机r=新随机();
双低=0.2;
双高=0.5;
双随机值=低+(高-低)*r.下一个双();
压力=压力-随机值;
压力设置文本(“压力:+压力+PSI”);
}
PSICount.start();
}
};
PSICount.start();
峰值=新的倒计时(300001000){
@凌驾
公共void onTick(长毫秒未完成){
}
@凌驾
公共无效onFinish(){
spike.start();
过热=过热+50;
过热设置文本(“系统热:+过热+”°C”);
高度=高度+1000;
高度设置文字(“高度:+alti+“ft”);
如果(速度<300 | |速度>300){
随机r=新随机();
int低=-50;
int高=50;
int结果=r.nextInt(高-低)+低;
速度=速度+结果;
speedT.setText(“速度:“+速度+”英里/小时”);
}
}
};
spike.start();
}
}

什么是“压力”的返回类型压力是双重的?如果您调试代码,我认为“高度”不>=30000,这就是为什么,如果运行此程序时条件变差,我可以看到高度值,它确实达到33000,一旦达到该值,占位符值消失,并被替换为零。它是这样做的另一个以前的双精度值,我刚刚改为整数,以节省时间,但现在我只是好奇为什么会发生这种情况。