以前一直都是用系统提供的日期选择控件,然后开发项目需要需要隐藏年月日等不同的组合。然后就从网上找了些Demo用,项目完成之后测试人员选择系统不同的年月日显示方式引起年月日显示的错位,卧槽!后来随之了解5.0以下的和以上的执行方式也不一样 ,只得改了,改完赶紧记录一下。
TimeDialog
public class TimeDialog extends Dialog { private DatePicker datePicker; private int type = 3; //1表示只显示年; 2表示显示年月 ;3表示显示年月日 //设置监听 时间 public interface myTimeListener{ public void timeListener(String time) ; }; public myTimeListener iTimeListener = null ; public void setTimeListener(myTimeListener listener) { iTimeListener = listener; } /* 1表示只显示年; 2表示显示年月 ;3表示显示年月日 */ public TimeDialog(Context context) { super(context); // TODO Auto-generated constructor stub setContentView(R.layout.time_dialog); initView(); } /* 1表示只显示年; 2表示显示年月 ;3表示显示年月日 */ public TimeDialog(Context context, int theme, int type) { super(context, theme)