Search code examples
androidstringintegerseekbar

How to seek seekbar to a specific region value obtained from a string?


I am having a seekbar and a time picker.

ie. Time will be stored in a string variable and it actually takes the current system time in 24-hour format. ie. like 16:23.

Calendar c= Calendar.getInstance();
SimpleDateFormat time_format= 
new SimpleDateFormat("HH:MM");
timeNow = time_format.format(c.getTime());
timeDisplay = (TextView)findViewById(R.id.map_time);
timeDisplay.setText(timeNow);

My problems are how to take this value into an integer like, if the current time is 16:23. I want 16 in an integer.

And also how to set the seekbar to this integer value when the page gets loaded?

mseekbar = (SeekBar)findViewById(R.id.map_seek); 

I have 24 intervals set in my seekbar. So i want the seekbar to be loaded by the previously converted integer value. Please help me out.


Solution

  • I've not tried either of these but I suggest...

    To get the hour use int hour = c.get(HOUR_OF_DAY);

    ...and to set the position of the Seekbar try mSeekBar.setProgress(hour - 1);