Currently trying to get two different values from the time picker reminderHour, which is the selectedHour and reminderMin which is the selectedMin. Thought I had it working perfectly but found another error this morning.
eReminderTime.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Calendar mcurrentTime = Calendar.getInstance();
int hour = mcurrentTime.get(Calendar.HOUR_OF_DAY);
int minute = mcurrentTime.get(Calendar.MINUTE);
TimePickerDialog mTimePicker;
mTimePicker = new TimePickerDialog(AddPayment.this, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {
reminderHour = selectedHour;
reminderMin = selectedMinute;
if (selectedHour < 10)
{
if(selectedMinute == 0)
{
eReminderTime.setText("0" + selectedHour + ":00" + selectedMinute);
}
else if(selectedMinute < 10)
{
eReminderTime.setText("0" + selectedHour + ":0" + selectedMinute);
}
else
{
eReminderTime.setText("0" + selectedHour + ":" + selectedMinute);
}
}
if (selectedHour == 0)
{
if(selectedMinute == 0)
{
eReminderTime.setText("0" + selectedHour + ":00" + selectedMinute);
}
else if(selectedMinute < 10)
{
eReminderTime.setText("0" + selectedHour + ":0" + selectedMinute);
}
else
{
eReminderTime.setText("0" + selectedHour + ":" + selectedMinute);
}
}
if(selectedMinute == 0)
{
eReminderTime.setText("" + selectedHour + ":00" + selectedMinute);
}
if(selectedMinute < 10)
{
eReminderTime.setText("" + selectedHour + ":0" + selectedMinute);
}
else
{
eReminderTime.setText( "" + selectedHour + ":" + selectedMinute);
}
}
}, hour, minute, true);
mTimePicker.setTitle("Select Time");
mTimePicker.show();
}
});
That's the code for my Time Picker. I don't want the time joined up all together because I need the hour value stored separately from the minute value.
I tried looking up SimpleDateFormat but I couldn't get it working. This is the code I tried
SimpleDateFormat simpleHour = new SimpleDateFormat("kk");
SimpleDateFormat simpleMin = new SimpleDateFormat("mm");
formatHour = simpleHour.format(selectedHour);
formatMin = simpleMin.format(selectedMinute);
reminderHour = Integer.parseInt(formatHour);
reminderMin = Integer.parseInt(formatMin);
Toast.makeText(getApplicationContext(), formatHour, 0).show();
Toast.makeText(getApplicationContext(), formatHour, 0).show();
That's because individual hh and mm aren't valid formats. Try to combine the minute and hour values together and when you receive the combined value, seperate them via
split()
e.g;