我的APP中有4个编辑文本,包含小时和分钟
double hour;
try {
hour= Double.parseDouble(dayhour.getText().toString().replace(',', '.'));
} catch (NumberFormatException e) {
hour = 0;
}
double minute;
try {
minute= Double.parseDouble(dayminute.getText().toString().replace(',', '.'));
} catch (NumberFormatException e) {
minute= 0;
}
double hour1;
try {
hour1= Double.parseDouble(dayhour1.getText().toString().replace(',', '.'));
} catch (NumberFormatException e) {
hour1= 0;
}
double minute1;
try {
minute1= Double.parseDouble(dayminute1.getText().toString().replace(',', '.'));
} catch (NumberFormatException e) {
minute1= 0;
}
如果未填写编辑文字小时的值,我该怎么做才能获得小时1的值?与分钟编辑文本相同的情况。
答案 0 :(得分:0)
如果你做了那个改变怎么办
try {
hour= Double.parseDouble(dayhour.getText().toString().replace(',', '.'));
} catch (NumberFormatException e) {
hour = null;
}
然后在执行完所有4个代码块之后进行测试:
if (hour==null) {
dayhour.setText("" + hour1);
}
答案 1 :(得分:0)
if(!TextUtils.isEmpty(dayhour.getText().toString()))
{
hour= Double.parseDouble(dayhour.getText().toString().replace(',', '.'));
}
else
{
hour= Double.parseDouble(dayhour1.getText().toString().replace(',', '.'));
// hour = hour1; // if you already have the value of hour1.
}
分钟和秒的相同方式