码迷,mamicode.com
首页 > 移动开发 > 详细

Android DatePickerDialog 只选择年月

时间:2014-05-09 04:36:00      阅读:532      评论:0      收藏:0      [点我收藏+]

标签:android   style   blog   class   code   java   

bubuko.com,布布扣
//对EditText注册OnTouch事件
etSscxNssbDate.setOnTouchListener(selectDateTouchListener);
bubuko.com,布布扣
bubuko.com,布布扣
//选择日期
    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;
        }
    };    
bubuko.com,布布扣
bubuko.com,布布扣
/**
     * 获取系统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;
    }
bubuko.com,布布扣

 

Android DatePickerDialog 只选择年月,布布扣,bubuko.com

Android DatePickerDialog 只选择年月

标签:android   style   blog   class   code   java   

原文地址:http://www.cnblogs.com/yshyee/p/3716118.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!