Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- 행복주택
- 일반근로자
- 3자녀우선
- 알뜰폰
- 강환국
- 국임
- sh공사
- 펜타카메라
- 국립항공박물관
- 통신3사
- AOFO Smart power
- 공공임대
- 스마트 멀티탭
- 시놀로지
- 퇴직한 직장인
- 공공분양
- 평강랜드
- 장기전세
- 가치투자
- 장전
- 워렌버핏
- KT
- 2018 공급계획
- 2017년 분양계획
- LG
- SH
- 국민임대
- 소득조회
- 분양
- AI 카메라
Archives
- Today
- Total
초코비니
DateTimePicker 본문
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
기본 사용법
public class MainActivity extends FragmentActivity implements OnDateSetListener, TimePickerDialog.OnTimeSetListener {
public static final String DATEPICKER_TAG = "datepicker";
public static final String TIMEPICKER_TAG = "timepicker";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Calendar calendar = Calendar.getInstance();
final DatePickerDialog datePickerDialog = DatePickerDialog.newInstance(this, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), isVibrate());
final TimePickerDialog timePickerDialog = TimePickerDialog.newInstance(this, calendar.get(Calendar.HOUR_OF_DAY) ,calendar.get(Calendar.MINUTE), false, false);
findViewById(R.id.dateButton).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
datePickerDialog.setVibrate(isVibrate());
datePickerDialog.setYearRange(1985, 2028);
datePickerDialog.setCloseOnSingleTapDay(isCloseOnSingleTapDay());
datePickerDialog.show(getSupportFragmentManager(), DATEPICKER_TAG);
}
});
findViewById(R.id.timeButton).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
timePickerDialog.setVibrate(isVibrate());
timePickerDialog.setCloseOnSingleTapMinute(isCloseOnSingleTapMinute());
timePickerDialog.show(getSupportFragmentManager(), TIMEPICKER_TAG);
}
});
if (savedInstanceState != null) {
DatePickerDialog dpd = (DatePickerDialog) getSupportFragmentManager().findFragmentByTag(DATEPICKER_TAG);
if (dpd != null) {
dpd.setOnDateSetListener(this);
}
TimePickerDialog tpd = (TimePickerDialog) getSupportFragmentManager().findFragmentByTag(TIMEPICKER_TAG);
if (tpd != null) {
tpd.setOnTimeSetListener(this);
}
}
}
private boolean isVibrate() {
return ((CheckBox) findViewById(R.id.checkBoxVibrate)).isChecked();
}
private boolean isCloseOnSingleTapDay() {
return ((CheckBox) findViewById(R.id.checkBoxCloseOnSingleTapDay)).isChecked();
}
private boolean isCloseOnSingleTapMinute() {
return ((CheckBox) findViewById(R.id.checkBoxCloseOnSingleTapMinute)).isChecked();
}
@Override
public void onDateSet(DatePickerDialog datePickerDialog, int year, int month, int day) {
Toast.makeText(MainActivity.this, "new date:" + year + "-" + month + "-" + day, Toast.LENGTH_LONG).show();
}
@Override
public void onTimeSet(RadialPickerLayout view, int hourOfDay, int minute) {
Toast.makeText(MainActivity.this, "new time:" + hourOfDay + "-" + minute, Toast.LENGTH_LONG).show();
}
}
'안드로이드' 카테고리의 다른 글
Comments