Android DatePickerDialog 只选择年月

//对EditText注册OnTouch事件
etSscxNssbDate.setOnTouchListener(selectDateTouchListener);
//选择日期
    private OnTouchListener selectDateTouchListener = new OnTouchListener(){
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if(event.getAction()==MotionEvent.ACTION_UP){
                final Calendar cd=Calendar.getInstance();
                Date date=new Date();
                cd.setTime(date);
                DatePickerDialog dp= new DatePickerDialog(getActivity(), new OnDateSetListener(){
                      public void onDateSet(DatePicker view, int year,int monthOfYear, int dayOfMonth) {
                          String dateStr = year+"-"+StrUtil.adjustMonthDay(monthOfYear+1);
                          
                          //当用户选择完年月之后,进行查询操作
                          if(PhoneInfo.isConnectInternet(getActivity())){
                             etSscxNssbDate.setText(dateStr);
                               doNssbQkSelect();
                            }else{
                               UIUtil.raDialog(getActivity(), WR.NET_NOT_CONN);
                            }
                      }
                      }, 
                      cd.get(Calendar.YEAR), 
                      cd.get(Calendar.MONTH),
                      cd.get(Calendar.DAY_OF_MONTH));
                dp.show();
                //隐藏天数
                if (dp != null) {
                    int SDKVersion = PhoneInfo.getSDKVersionNumber();
                    if (SDKVersion < 11) {
                        ((ViewGroup) dp.getDatePicker().getChildAt(0)).getChildAt(2).setVisibility(View.GONE);
                    } else if (SDKVersion > 14) {
                        ((ViewGroup) ((ViewGroup) dp.getDatePicker().getChildAt(0)).getChildAt(0)).getChildAt(2).setVisibility(View.GONE);
                    }
                }
                etSscxNssbDate.setInputType(InputType.TYPE_NULL);  
            }
            return false;
        }
    };    
/**
     * 获取系统SDK版本
     * @return
     */
    public static int getSDKVersionNumber() {
        int sdkVersion;
        try {
            sdkVersion = Integer.valueOf(android.os.Build.VERSION.SDK_INT);
        } catch (NumberFormatException e) {
            sdkVersion = 0;
        }
        return sdkVersion;
    }

 

Android DatePickerDialog 只选择年月,,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。