I created a simple TimePickerDialog, they work fine, but if I set the current time in the time collector, then the problem is to set AM and PM.
we will see....
If the current time is 5:39 pm
this is my code.
Calendar cal = Calendar.getInstance();
int mHour = cal.get(Calendar.HOUR_OF_DAY);
int mMinute = cal.get(Calendar.MINUTE);
int mTimeSet=cal.get(Calendar.AM_PM);
TimePickerDialog tpd = new TimePickerDialog(this,new TimePickerDialog.OnTimeSetListener()
{
@Override
public void onTimeSet(TimePicker view, int hours,int minute)
{
String timeSet = "";
if (hours > 12) {
hours -= 12;
timeSet = "PM";
} else if (hours == 0) {
hours += 12;
timeSet = "AM";
} else if (hours == 12)
timeSet = "PM";
else
timeSet = "AM";
String minutes="";
if (minute < 10)
minutes = "0" + minute;
else
minutes = String.valueOf(minute);
textView.setText(hours + ":" + minutes + " " + timeSet);
}
}, mHour, mMinute,false);
tpd.show();
Result

But how to set PM in the timing dialog? please any decision
source
share