2016-09-23 68 views
0
private TimePickerDialog.OnTimeSetListener timeListener = new TimePickerDialog.OnTimeSetListener() { 
    @Override 
    public void onTimeSet(TimePicker view, int hourOfDay, int minute) { 

     if(hourOfDay < 10){ 
      strHourOfDay = "0" + hourOfDay; 
     } else { strHourOfDay = String.valueOf(hourOfDay);} 

     if(minute < 10){ 
      strMinute = "0" + minute; 
     } else { strMinute = String.valueOf(minute);} 

     period.put("hour",strHourOfDay); 
     period.put("minute",strMinute); 

     periodTime.setText(strHourOfDay + ":" + strMinute); 
    } 
}; 

我使用TimePickerDialog保存小時和分鐘。在strHourOfDay中成功輸入了小時天數的小數點輸入日期。不過分鐘未能在strMinute輸入..timepickerdialog分鐘輸入錯誤

調試結果是在畫面

enter image description here

有什麼錯?

+0

發表您的logcat – Lingeshwaran

回答

0

始終使用;

String.valueOf(minute); 

如果你想解析數(爲float,double的int,long),以String

所以,你的代碼應該是這樣的:

if(minute < 10) { 
     strMinute = "0" + String.valueOf(minute); 
} else { 
     strMinute = String.valueOf(minute); 
}