我遇到了一个与我的程序有关的问题,我的textveiw不会显示任何小数,继承人发生了什么事情。用户在textEdit中输入一个数字(我怎么让文本编辑器只接受数字和一个小数点?)这个数字被转换为一个int,发送给我的第二个活动,被3600潜入,然后显示在textveiw框中。问题是,当这个数字显示时,它没有小数值,例如,如果它小于1它不会显示任何东西,我怎么能解决这个问题?我需要它至少去第1000个地方。 这里是我的代码一个活动1:textView不会显示小数
public void sendMessage(View view) {
// Do something in response to button
Intent intent = new Intent(this, PayTracker.class);
// Gather text from text boxes
EditText editText = (EditText) findViewById(R.id.hourly_wage);
//Create String from text
String message1 = editText.getText().toString();
//Convert String to Int
int HW = 0;
try{
HW = Integer.valueOf(message1);
}
catch(NumberFormatException nfe){
//do something else here
//for e.g. initializing default values to your int variables
}
// Send Integers to PayTracker.java
intent.putExtra(MESSAGE_HW, HW);
// start new activity
startActivity(intent);
然后这是活性2其中数字需要显示:
public void sendMessage(View view) {
// Receive messages from options page
Intent intent = getIntent();
int HW = intent.getIntExtra(Options.MESSAGE_HW, 0);
// Calculate pay per second
int PPS = 0;
PPS = (HW/3600);
// set textView
TextView textView = (TextView) this.findViewById(R.id.yourpay);
textView.setText(String.valueOf(PPS));
}
任何帮助,将不胜感激!谢谢!
声明为**浮动PPS = 0F; ** – 2012-07-27 13:42:14