日期控件(只要年月)

关键代码: ((ViewGroup)((ViewGroup) dp.getChildAt(0)).getChildAt(0)).getChildAt(2).setVisibility(View.GONE);//隐藏日
	/**
	 * 选择日期控件
	 */
	public void PickDate()
	{
		calendar = Calendar.getInstance();
/*		new DatePickerDialog(MonthMoneyListActivity. this ,datePickListener ,calendar .get(Calendar. YEAR ),calendar .get(Calendar. MONTH ),calendar .get(Calendar. DAY_OF_MONTH )
						).show();*/
		
		DatePickerDialog mDialog = new DatePickerDialog(YearMoneyPicActivity. this ,datePickListener ,calendar .get(Calendar. YEAR ),calendar .get(Calendar. MONTH ),calendar .get(Calendar. DAY_OF_MONTH ));
		mDialog.show();
		DatePicker dp = findDatePicker((ViewGroup) mDialog.getWindow().getDecorView());  
		if (dp != null) 
		{  
			((ViewGroup)((ViewGroup) dp.getChildAt(0)).getChildAt(0)).getChildAt(2).setVisibility(View.GONE);//隐藏日		}

		
	}
	private DatePickerDialog.OnDateSetListener datePickListener = new DatePickerDialog.OnDateSetListener()
	{ 
		@Override
		public void onDateSet(DatePicker arg0, int arg1, int arg2, int arg3)
		{
			calendar .set(Calendar. YEAR , arg1);
			calendar .set(Calendar. MONTH , arg2);
			calendar .set(Calendar. DAY_OF_MONTH , arg3);
			updateDate();
		}
	};
	// 当 DatePickerDialog 关闭,更新日期显示
	private void updateDate()
	{
		sdf = new SimpleDateFormat( "yyyy-MM-dd" );
		year_pic_time.setText(sdf.format( calendar.getTime()).substring(0,4));
	}
	//通过遍历方法查找DatePicker里的子控件:年、月、日
	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;  
	 }   


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值