关键代码: ((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;
}