Ejemplo n.º 1
0
 private void setEndTime(final TimeObject startTime) {
   LinearLayout layout = new LinearLayout(PlayBackActivity.this);
   layout.setOrientation(LinearLayout.VERTICAL);
   layout.setBackgroundColor(getResources().getColor(R.color.white));
   final TimePicker mTimePicker = new TimePicker(PlayBackActivity.this);
   final DatePicker mDatePicker = new DatePicker(PlayBackActivity.this);
   mTimePicker.setDescendantFocusability(TimePicker.FOCUS_BLOCK_DESCENDANTS);
   mTimePicker.setIs24HourView(true);
   mDatePicker.setDescendantFocusability(DatePicker.FOCUS_BLOCK_DESCENDANTS);
   final TextView tv = new TextView(PlayBackActivity.this);
   String time = String.format("%02d:%02d", startTime.getHour(), startTime.getMinute());
   String date =
       String.valueOf(startTime.getYear())
           + "年"
           + String.format("%02d", startTime.getMonth())
           + "月"
           + String.format("%02d", startTime.getDay())
           + "日";
   tv.setText("开始时间:" + date + "  " + time);
   int version = Integer.valueOf(android.os.Build.VERSION.SDK);
   if (version >= 11) mDatePicker.setCalendarViewShown(false);
   layout.addView(tv, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
   layout.addView(
       mDatePicker, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
   layout.addView(
       mTimePicker, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
   new AlertDialog.Builder(PlayBackActivity.this)
       .setTitle("请选择结束时间:")
       .setView(layout)
       .setPositiveButton(
           android.R.string.ok,
           new DialogInterface.OnClickListener() {
             @Override
             public void onClick(DialogInterface arg0, int arg1) {
               TimeObject endTime =
                   new TimeObject(
                       mTimePicker.getCurrentMinute(),
                       mTimePicker.getCurrentHour(),
                       mDatePicker.getDayOfMonth(),
                       mDatePicker.getMonth() + 1,
                       mDatePicker.getYear());
               System.out.println("时间:" + endTime.getMinute() + "  " + startTime.getMinute());
               onTimeSearch(startTime, endTime);
             }
           })
       .setNegativeButton(
           android.R.string.cancel,
           new DialogInterface.OnClickListener() {
             @Override
             public void onClick(DialogInterface arg0, int arg1) {}
           })
       .create()
       .show();
 }