public static void displayDatePickerDialogWithoutDaySection( Context context, final TextView datePicker) { // 날짜가 표시합니다 // 오늘 날짜를 가져옵니다 Calendar c = Calendar.getInstance(); final int cyear = c.get(Calendar.YEAR); final int cmonth = c.get(Calendar.MONTH); final int cday = c.get(Calendar.DAY_OF_MONTH); MyDatePickerDialog.OnDateSetListener mDateSetListener = new MyDatePickerDialog.OnDateSetListener() { public void onDateSet(android.widget.DatePicker view, int year, int monthOfYear, int dayOfMonth) { String date_selected = String.valueOf(year) + "-" + String.valueOf(monthOfYear + 1); datePicker.setText(date_selected); } }; MyDatePickerDialog datePickerDialog = new MyDatePickerDialog(context, mDateSetListener, cyear, cmonth, cday); datePickerDialog.show(); DatePicker dp = findDatePicker((ViewGroup) datePickerDialog.getWindow() .getDecorView()); try { Field f[] = dp.getClass().getDeclaredFields(); for (Field field : f) { if (field.getName().equals("mDaySpinner") || field.getName().equals("mDayPicker")) { field.setAccessible(true); Object dayPicker = new Object(); dayPicker = field.get(dp); ((View) dayPicker).setVisibility(View.GONE); } } } catch (SecurityException e) { Log.d("ERROR", e.getMessage()); } catch (IllegalArgumentException e) { Log.d("ERROR", e.getMessage()); } catch (IllegalAccessException e) { Log.d("ERROR", e.getMessage()); } String currentDate = String.valueOf(cyear) + "년 " + String.valueOf(cmonth + 1) + "월"; datePickerDialog.setTitle(currentDate); }
-------------------------------------------------------------------------------
<MyDatePickerDialog.java>
package kr.co.ht.smartsales.utils; import java.util.Calendar; import android.app.DatePickerDialog; import android.content.Context; import android.content.DialogInterface; import android.text.format.DateUtils; import android.widget.DatePicker; public class MyDatePickerDialog extends DatePickerDialog { public MyDatePickerDialog(Context context, OnDateSetListener callBack, int year, int monthOfYear, int dayOfMonth) { super(context, callBack, year, monthOfYear, dayOfMonth); // TODO Auto-generated constructor stub } @Override public void onDateChanged(DatePicker view, int year, int month, int day) { view.init(year, month, day, this); updateTitle(year, month, day); } private void updateTitle(int year, int month, int day) { String chosenDate = String.valueOf(year) + "년 " + String.valueOf(month + 1) + "월"; setTitle(chosenDate); } }
댓글 없음:
댓글 쓰기