天天看點

DatePickerDialog使用

調用

DatePickerDialog dialog = new DatePickerDialog(MainActivity.this, THEME_HOLO_LIGHT, new DatePickerDialog.OnDateSetListener() {
     @Override
     public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
        //對選擇的日期進行處理
 }, int year,int month-1,int day);
dialog.show();      
THEME_HOLO_LIGHT : theme設定       
請參考:http://blog.csdn.net/lckj686/article/details/19552793      
修改顯示的條目數:年、月、日的選擇:      
不顯示日:      
DatePicker dp = findDatePicker((ViewGroup) dialog1.getWindow()
        .getDecorView());
if (dp != null) {

        View view = ((ViewGroup) ((ViewGroup) dp.getChildAt(0))
                .getChildAt(0)).getChildAt(2);
        view.setVisibility(View.GONE);
}      
private DatePicker findDatePicker(ViewGroup group) {
    if (group != null) {
        for (int i = 0, j = group.getChildCount(); i < j; i++) {
            View child = group.getChildAt(i);
            if (child instanceof DatePicker) {
                return (DatePicker) child;
            } else if (child instanceof ViewGroup) {
                DatePicker result = findDatePicker((ViewGroup) child);
                if (result != null)
                    return result;
            }
        }
    }
    return null;
}      
請參考:http://blog.csdn.net/lzt623459815/article/details/8479991

繼續閱讀