I want to create spinner which has
8:00-8:30 AM
8:30-9:00 AM
9:00-9:30 AM
time slot I done with the ArrayList like
8:00 AM
9:00 AM
10:00 AM
and so on.
I got the arraylist like
ArrayList[08:00:AM, 09:00:AM, 10:00:AM, 11:00:AM, 12:00:PM, 13:00:PM, 14:00:PM, 15:00:PM, 16:00:PM, 17:00:PM, 18:00:PM, 19:00:PM, 20:00:PM, 21:00:PM]
This is my code:
public class MainActivity extends AppCompatActivity {
ArrayList<String> hours = new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initCustomTimeSpinner();
}
private void initCustomTimeSpinner() {
Spinner spinnerCustom = (Spinner) findViewById(R.id.spinner2);
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:a");
SimpleDateFormat startHourFormat = new SimpleDateFormat("HH");
cal.set(Calendar.HOUR_OF_DAY, 8);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
int startHour = Integer.parseInt(startHourFormat.format(cal.getTime()));
Log.e("startHour", Integer.toString(startHour));
Log.e("withot format Starttime", cal.getTime().toString());
SimpleDateFormat endHourFormat = new SimpleDateFormat("HH");
cal.set(Calendar.HOUR_OF_DAY, 21);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
int endHour = Integer.parseInt(endHourFormat.format(cal.getTime()));
Log.e("endHour", Integer.toString(endHour));
Log.e("withot format End time", cal.getTime().toString());
String test = sdf.format(cal.getTime());
Log.e("TEST", test);
for (int i = startHour; i <= endHour; i++) {
cal.set(Calendar.HOUR_OF_DAY, i);
hours.add(sdf.format(cal.getTime()));
System.out.println("ArrayList" + hours);
}
}
}