我正在制作一款需要三个时间选择器的应用。每个时间选择器都在我点击监听器上的按钮中定义。
// What Happens When Item Is Clicked//
@Override
public void onClick(View v) {
switch(v.getId()) {
// What Happens When Select Time Button Is Clicked//
case R.id.SelectTime:
// Create Calender Instance//
final Calendar calendar = Calendar.getInstance();
final TimePickerDialog timePickerDialog = TimePickerDialog.newInstance
(this, calendar.get(Calendar.HOUR_OF_DAY) ,calendar.get(Calendar.MINUTE), false, false);
timePickerDialog.setVibrate(isVibrate());
timePickerDialog.show(getSupportFragmentManager(), TIMEPICKER_TAG);
break;
// What Happens When Select Time End Button Is Clicked//
case R.id.SelectTimeEnd:
// Create Calender Instance//
final Calendar calendar2 = Calendar.getInstance();
final TimePickerDialog timePickerDialog2 = TimePickerDialog.newInstance
(this, calendar2.get(Calendar.HOUR_OF_DAY) ,calendar2.get(Calendar.MINUTE), false, false);
timePickerDialog2.setVibrate(isVibrate());
timePickerDialog2.show(getSupportFragmentManager(), TIMEPICKER_TAG2);
break;
}
}
然后将其转移到此处,以便可以在文本视图中读取时间。
//Controls Time//
@Override
public void onTimeSet(RadialPickerLayout view, int hourOfDay, int minute) {
String timeSet = "";
if (hourOfDay > 12) {
hourOfDay -= 12;
timeSet = "PM";
} else if (hourOfDay == 0) {
hourOfDay += 12;
timeSet = "AM";
} else if (hourOfDay == 12)
timeSet = "PM";
else
timeSet = "AM";
String min = "";
if (minute < 10)
min = "0" + minute;
else
min = String.valueOf(minute);
// Append in a StringBuilder
String aTime = new StringBuilder().append(hourOfDay).append(':')
.append(min).append(" ").append(timeSet).toString();
sttime.setText(aTime);
}
}
问题是,当我将另一个时间选择器用于另一个按钮时,它只能识别相同的文本视图,如何创建多个onTime集,以便我可以在同一个活动中拥有所有三个时间选择器?