gpt4 book ai didi

java - 不将数字选择器十进制整数传递给新 Activity

转载 作者:行者123 更新时间:2023-12-01 10:14:50 25 4
gpt4 key购买 nike

我正在将 Integer 从 numberPicker 传递到新的 Activity。问题是所选值在新 Activity 中未显示十进制值。如果我选择 90 并单击“确定”按钮进入新 Activity ,则会显示 9。这是我的代码:

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

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

button.setOnClickListener(
new Button.OnClickListener(){

@Override
public void onClick(View v) {
NumberPicker numberPicker= (NumberPicker) findViewById(R.id.numberPicker);
int x=numberPicker.getValue();
Intent intent= new Intent(MainActivity.this,Main22Activity.class);
intent.putExtra("roundtime",x);
startActivity(intent);


}
}
);

String [] time= new String[10];
for(int i=0;i<time.length;i++){
time[i]=Integer.toString(i*10);
}
NumberPicker numberPicker= (NumberPicker) findViewById(R.id.numberPicker);
numberPicker.setMaxValue(time.length-1);
numberPicker.setMinValue(0);
numberPicker.setWrapSelectorWheel(true);
numberPicker.setDisplayedValues(time);

}

}

这是我的第二个 Activity :

    Intent intent = getIntent();

int msg=intent.getIntExtra("roundtime",0);
TextView textView=(TextView)findViewById(R.id.textView3);
textView.setText(Integer.toString(msg));
}

最佳答案

如果你想要decimal值,为什么要使用int?请改用double

如果你将选择器上的Max设置为9,你如何选择“90”?

关于java - 不将数字选择器十进制整数传递给新 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35961679/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com