kiran kiran - 14 days ago 8
Android Question

How to pass string in android TimePicker

I have to pass hours and minutes into calendar.set method.

My code:

String smsBody=getIntent().getExtras().getString("smsBody");
String msg = smsBody.toString();
String[] time = msg.split(":");
String Hours = time[0];
String Minutes = time[1];
Calendar calendar = Calendar.getInstance();

//The problem comes here

//Hours
calendar.set(Calendar.HOUR_OF_DAY, alarmTimePicker.getCurrentHour());

//Minutes
calendar.set(Calendar.MINUTE, alarmTimePicker.getCurrentMinute());

Answer

Try this :

String smsBody=getIntent().getExtras().getString("smsBody");
String msg = smsBody.toString();
String[] time = msg.split(":");
int Hours = Integer.parseInt(time[0]);
int Minutes = Integer.parseInt(time[1]);

alarmTimePicker.setCurrentHour(Hours);
alarmTimePicker.setCurrentMinute(Minutes);