大佬教程收集整理的这篇文章主要介绍了Android将DatePicker设置为特定日期,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
String mday = "02"; String mmonth="07"; String myear="2013";
我需要将活动中的DatePicker设置为从上面的日期开始的一个月.我并不是说只是将1加到mmonth值……如果是第31天,我最终会得到一个无效的日期.
所以我需要一些方法来增加日期(有效的方式)并设置DatePicker的值.
我知道使用Int值设置datePicker是这样的:
DatePicker datepicker = (DatePicker) findViewById(R.id.datePicker1); datepicker.init(iYear,iMonth,iDay,null); // where iYear,iMonth and iDay are Integers
但是如何获得递增DATE的日,月和年的整数值一个月?
那么在第一个值(字符串)和递增日期的最终值(整数)之间我必须做出哪些步骤?
Integer iYear,iDay = 0; String mday = "02"; String mmonth="07"; String myear="2013"; Calendar cal = Calendar.geTinstance(); cal.set(Integer.parseInt(myear),Integer.parseInt(mmonth),Integer.parseInt(mday)); cal.add(Calendar.MONTH,1); // here I should get the values from cal inside the iYear,but I do not seem to succeed. DatePicker datepicker = (DatePicker) findViewById(R.id.datePicker1); datepicker.init(iYear,null);
如果我做:
datepicker.init(cal.YEAR,cal.MONTH,cal.DATE,null);
然后应用程序崩溃.
我该怎么办?
如何将这个月份日期增加到我的DatePicker?
Calendar cal = Calendar.geTinstance(); cal.set(2013,05,23); cal.add(Calendar.MONTH,1); int xxday = cal.get(Calendar.DATE); int xxmonth = cal.get(Calendar.MONTH); int xxyear = cal.get(Calendar.YEAR); datepicker.init(xxyear,xxmonth,xxday,null);
但是现在datePicker从现在开始设置为一个月,而不是从想要的日期开始一个月而不是(2013-06-23)我有(2013-09-23).我认为这是因为
int xxmonth = cal.get(Calendar.MONTH);
如何从Calendar cal获得真实的月份; ?
以上是大佬教程为你收集整理的Android将DatePicker设置为特定日期全部内容,希望文章能够帮你解决Android将DatePicker设置为特定日期所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。