TimePicker 사용하기

<timepicker사용해서 특정값으로 세팅하기>
try {

date2 = sdf2.parse(여기에시간 넣는다 “2015-11-10”);            Toast.makeText(ThirdActivity.this, “5:”+time, Toast.LENGTH_LONG).show();

}catch (java.text.ParseException e) {

// TODO Auto-generated catch block e.printStackTrace(); }

Calendar mCalendar;

mCalendar = Calendar.getInstance();

mCalendar.setTime(date2); //Calendar에 시간을 set하고..  Toast.makeText(ThirdActivity.this, “6:”+time, Toast.LENGTH_LONG).show();       TimePicker picker = new TimePicker(getApplicationContext());        mTimePicker.setCurrentHour(mCalendar.get(Calendar.HOUR_OF_DAY)); //timepicker에 넣는다.

mTimePicker.setCurrentMinute(mCalendar.get(Calendar.MINUTE));
https://stackoverflow.com/questions/12494074/android-setting-time-in-time-picker-with-the-time-shown-in-text-view

<timepicker에서 현재 선택된 값 가져오기>

Integer hour = mTimePicker.getCurrentHour();

Integer min = mTimePicker.getCurrentMinute();

<layout에 넣는 방법>

<TimePicker
    android:id="@+id/timePicker"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="17dp"
    android:layout_centerHorizontal="true"
    android:timePickerMode="spinner" />

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s