I have a initial Time value of 10:30. I also have two SeekBar one for number of hours and other for number of minutes.
When I slide the SeekBar to a certain value, for example for the Hour SeekBar, the number of hours get added to the initial time of 10:30. This works fine.
Further if I again drag the SeekBar to a new value, that value should be added to the initial value and not the value I obtain after the first drag.
ie. If at first I drag the SeekBar to 1 hour and leave the SeekBar, the time is 11.30.
If again I drag the value to 3 hours, the 3 hours get added to 11.30 making the time 2:30 whereas I want the time to be 1:30
Here is my code:-
String initialTime = "10:30"
cal = Calendar.getInstance();
DateFormat sdf = new SimpleDateFormat("hh:mm:ss");
Date date;
try
{
date = sdf.parse(initialTime);
cal= Calendar.getInstance();
cal.setTime(date);
txtReachingBy.setText("Reaching By:"+" "+ cal.get(Calendar.HOUR_OF_DAY)+":"+cal.get(Calendar.MINUTE));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
seekLateBy.setOnSeekBarChangeListener(new OnSeekBarChangeListener()
{
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
{
progressChangedHours = progress;
if(progressChangedHours==0 && progressChangedMins!=0)
{
lblLateBy.setText("Late By (Hrs):"+" " + String.valueOf(progressChangedHours) +":"+String.valueOf(progressChangedMins));
}
else
lblLateBy.setText("Late By (Hrs):"+" " + String.valueOf(progressChangedHours) +":"+String.valueOf(progressChangedMins));
}
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
public void onStopTrackingTouch(SeekBar seekBar)
{
if(progressChangedHours==0)
{
timeString = cal.get(Calendar.HOUR_OF_DAY)+":"+cal.get(Calendar.MINUTE)+":"+today.second;
}
else
{
cal.add(Calendar.HOUR_OF_DAY, progressChangedHours);
timeString = cal.get(Calendar.HOUR_OF_DAY)+":"+cal.get(Calendar.MINUTE)+":"+today.second;
}
txtReachingBy.setText("Reaching by:"+" "+timeString);
}
});
How can I do this/
0 comments:
Post a Comment