android.widget.TimePicker类的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(120)

本文整理了Java中android.widget.TimePicker类的一些代码示例,展示了TimePicker类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TimePicker类的具体详情如下:
包路径:android.widget.TimePicker
类名称:TimePicker

TimePicker介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

protected void onBindDialogView(View v) {
  super.onBindDialogView(v);
  picker.setCurrentHour(calendar.get(Calendar.HOUR_OF_DAY));
  picker.setCurrentMinute(calendar.get(Calendar.MINUTE));
    calendar.set(Calendar.HOUR_OF_DAY, picker.getCurrentHour());
    calendar.set(Calendar.MINUTE, picker.getCurrentMinute());

代码示例来源:origin: stackoverflow.com

timePicker.setOnTimeChangedListener(new OnTimeChangedListener() {
  @Override
  public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
if (!dialog.isShowing()) {
  if (calendar_date == null)
    calendar_date = Calendar.getInstance();
  selectedHour = calendar_date.get(Calendar.HOUR_OF_DAY);
  selectedMinute = calendar_date.get(Calendar.MINUTE);
  timePicker.setIs24HourView(is24HourView);
  timePicker.setCurrentHour(selectedHour);
  timePicker.setCurrentMinute(selectedMinute);
  datePicker.updateDate(calendar_date.get(Calendar.YEAR),
      calendar_date.get(Calendar.MONTH),
      calendar_date.get(Calendar.DATE));
    int month = datePicker.getMonth();
    int year = datePicker.getYear();
    int day = datePicker.getDayOfMonth();

代码示例来源:origin: ankidroid/Anki-Android

@Override
protected View onCreateDialogView() {
  timePicker = new TimePicker(getContext());
  timePicker.setIs24HourView(true);
  return timePicker;
}

代码示例来源:origin: RobotiumTech/robotium

public void run()
  {
    try{
      timePicker.setCurrentHour(hour);
      timePicker.setCurrentMinute(minute);
    }catch (Exception ignored){}
  }
});

代码示例来源:origin: stackoverflow.com

SimpleDateFormat sdf = new SimpleDateFormat("hh:ss");
   Date date = null;
   try {
     date = sdf.parse("07:00");
   } catch (ParseException e) {
   }
   Calendar c = Calendar.getInstance();
   c.setTime(date);
   TimePicker picker = new TimePicker(getApplicationContext());
   picker.setCurrentHour(c.get(Calendar.HOUR_OF_DAY));
   picker.setCurrentMinute(c.get(Calendar.MINUTE));

代码示例来源:origin: termux/termux-api

@Override
String getResult() {
  String result;
  if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
    result = String.format(Locale.getDefault(), "%02d:%02d", widgetView.getHour(), widgetView.getMinute());
  } else {
    result = String.format(Locale.getDefault(), "%02d:%02d", widgetView.getCurrentHour(), widgetView.getCurrentMinute());
  }
  return result;
}

代码示例来源:origin: CUTR-at-USF/OpenTripPlanner-for-Android

@Override
  public void onClick(View v) {
    Calendar cal = Calendar.getInstance();
    cal.set(pickerDate.getYear(), pickerDate.getMonth(), pickerDate.getDayOfMonth(),
        pickerTime.getCurrentHour(), pickerTime.getCurrentMinute());
    ArriveBySpinnerItem selectedSscheduleType = (ArriveBySpinnerItem) spinScheduleType
        .getSelectedItem();
    ((MyActivity) getActivity())
        .onDateComplete(cal.getTime(), selectedSscheduleType.getValue());
    dismiss();
  }
};

代码示例来源:origin: stackoverflow.com

public class TimePickerDemoActivity extends Activity implements
  OnTimeChangedListener {
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

  TimePicker picker=(TimePicker)findViewById(R.id.picker);

  picker.setOnTimeChangedListener(this);
 }

 @Override
 public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
  Calendar then=Calendar.getInstance();

  then.set(Calendar.HOUR_OF_DAY, hourOfDay);
  then.set(Calendar.MINUTE, minute);
  then.set(Calendar.SECOND, 0);

  Toast.makeText(this, then.getTime().toString(), Toast.LENGTH_SHORT)
     .show();
 }
}

代码示例来源:origin: oliexdev/openScale

@Override
protected View getInputView() {
  TimePicker timePicker = new TimePicker(getContext());
  timePicker.setPadding(0, 15, 0, 0);
  Calendar cal = Calendar.getInstance();
  cal.setTime(time);
  timePicker.setCurrentHour(cal.get(Calendar.HOUR_OF_DAY));
  timePicker.setCurrentMinute(cal.get(Calendar.MINUTE));
  timePicker.setIs24HourView(android.text.format.DateFormat.is24HourFormat(getContext()));
  return timePicker;
}

代码示例来源:origin: stackoverflow.com

Conference conference2 = ConferenceBuilder.conference()
      .id(idConf)
      .importance(Double.parseDouble(importance.getSelectedItem().toString()))
      .title(title.getText().toString())
      .body(body.getText().toString())
      .location(location.getText().toString())
      // yyyy/MM/dd HH:mm:ss
      .timeInMilliseconds(getTimeInMillis(datePicker, timePicker))
      .build();
}

private long getTimeInMillis(DatePicker datePicker, TimePicker timePicker) {
  Calendar calendar = Calendar.getInstance();
  calendar.set(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth(), 
  timePicker.getCurrentHour(), timePicker.getCurrentMinute(), 0);
  return calendar.getTimeInMillis();
}

代码示例来源:origin: stackoverflow.com

@Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_profile);
   TimePicker timePicker=(TimePicker)findViewById(R.id.timePicker);
   timePicker.setIs24HourView(true);//set Timer to 24 hours Format
   timePicker.setCurrentHour(Calendar.getInstance().get(Calendar.HOUR_OF_DAY));
   int hours= timePicker.getCurrentHour();//get Time in 24 Hours using time Picker
 }

代码示例来源:origin: stackoverflow.com

TimePicker picker = (TimePicker) findViewById(R.id.timePicker1);
 picker.setIs24HourView(true);
 Calendar calendar = Calendar.getInstance();
 int h = calendar.get(Calendar.HOUR_OF_DAY);
 int m = calendar.get(Calendar.MINUTE);
 picker.setCurrentHour(h);
 picker.setCurrentMinute(m);

代码示例来源:origin: stackoverflow.com

final View dialogView = View.inflate(activity, R.layout.date_time_picker, null);
final AlertDialog alertDialog = new AlertDialog.Builder(activity).create();

dialogView.findViewById(R.id.date_time_set).setOnClickListener(new View.OnClickListener() {
  @Override
  public void onClick(View view) {

     DatePicker datePicker = (DatePicker) dialogView.findViewById(R.id.date_picker);
     TimePicker timePicker = (TimePicker) dialogView.findViewById(R.id.time_picker);

     Calendar calendar = new GregorianCalendar(datePicker.getYear(),
              datePicker.getMonth(),
              datePicker.getDayOfMonth(),
              timePicker.getCurrentHour(),
              timePicker.getCurrentMinute());

     time = calendar.getTimeInMillis();
     alertDialog.dismiss();
  }});
alertDialog.setView(dialogView);
alertDialog.show();

代码示例来源:origin: oliexdev/openScale

@Override
protected void onBindDialogView(View v) {
  super.onBindDialogView(v);
  picker.setCurrentHour(calendar.get(Calendar.HOUR_OF_DAY));
  picker.setCurrentMinute(calendar.get(Calendar.MINUTE));
}

代码示例来源:origin: annathehybrid/Github

@TargetApi(Build.VERSION_CODES.M)
@Override
public void onClick(View v) {
  calendar.set(Calendar.HOUR_OF_DAY, alarmTimePicker.getHour());
  calendar.set(Calendar.MINUTE, alarmTimePicker.getMinute());
  final int hour = alarmTimePicker.getHour();
  final int minute = alarmTimePicker.getMinute();;
  String minute_string = String.valueOf(minute);
  String hour_string = String.valueOf(hour);
  if (minute < 10) {
    minute_string = "0" + String.valueOf(minute);
  }
  if (hour > 12) {
    hour_string = String.valueOf(hour - 12) ;
  }
  myIntent.putExtra("extra", "yes");
  myIntent.putExtra("quote id", String.valueOf(richard_quote));
  pending_intent = PendingIntent.getBroadcast(MainActivity.this, 0, myIntent, PendingIntent.FLAG_UPDATE_CURRENT);
  alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pending_intent);
  setAlarmText("Alarm set to " + hour_string + ":" + minute_string);
}

代码示例来源:origin: renyuneyun/Easer

private static void setTimePicker(TimePicker timePicker, Calendar calendar) {
  int hour, minute;
  hour = calendar.get(Calendar.HOUR_OF_DAY);
  minute = calendar.get(Calendar.MINUTE);
  if (Build.VERSION.SDK_INT >= 23) {
    timePicker.setHour(hour);
    timePicker.setMinute(minute);
  } else {
    timePicker.setCurrentHour(hour);
    timePicker.setCurrentMinute(minute);
  }
}

代码示例来源:origin: quemb/QMBForm

@SuppressWarnings("deprecation")
@Override
protected void initDatePicker(Calendar calendar) {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
  {
    mTimePicker.setHour(calendar.get(Calendar.HOUR_OF_DAY));
    mTimePicker.setMinute(calendar.get(Calendar.MINUTE));
  }
  else
  {
    mTimePicker.setCurrentHour(calendar.get(Calendar.HOUR_OF_DAY));
    mTimePicker.setCurrentMinute(calendar.get(Calendar.MINUTE));
  }
  mTimePicker.setOnTimeChangedListener(this);
  if (DateFormat.is24HourFormat(getContext()))
      mTimePicker.setIs24HourView(true);
}

代码示例来源:origin: dsolonenko/financisto

private void prepareDialog(Dialog dialog, Calendar c) {
  DatePicker dp = dialog.findViewById(R.id.date);
  dp.init(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH), null);
  TimePicker tp = dialog.findViewById(R.id.time);
  tp.setIs24HourView(is24HourFormat(this));
  tp.setCurrentHour(c.get(Calendar.HOUR_OF_DAY));
  tp.setCurrentMinute(c.get(Calendar.MINUTE));
}

代码示例来源:origin: SecUSo/privacy-friendly-pedometer

@Override
protected void onBindDialogView(View v) {
  super.onBindDialogView(v);
  setHour(picker, calendar.get(Calendar.HOUR_OF_DAY));
  setMinute(picker, calendar.get(Calendar.MINUTE));
  picker.setIs24HourView(DateFormat.is24HourFormat(getContext()));
}

代码示例来源:origin: stackoverflow.com

super.onBindDialogView(v);
picker.setCurrentHour(lastHour);
picker.setCurrentMinute(lastMinute);
  lastHour=picker.getCurrentHour();
  lastMinute=picker.getCurrentMinute();

相关文章