我需要帮助,为此代码添加282天
public void onClick_add282(View v) {
TextView tv_output;
tv_output = (TextView) findViewById(R.id.tv_output);
dPicker = (DatePicker)findViewById(R.id.dp_cal);
Integer dYear = dPicker.getYear();
Integer dMonth = dPicker.getMonth()+1;
Integer dDate = dPicker.getDayOfMonth();
StringBuilder ad=new StringBuilder();
ad.append(dDate.toString()).append("-").append(dMonth.toString()).append("-").append(dYear.toString()).append("");
String dStr=ad.toString();
tv_output.setText(dStr);
}
我试图像这样添加282到这一行
Integer dDate = dPicker.getDayOfMonth()+282;
它返回300-6-2014(今天是我居住的18-6-2014)
编辑:我没有尝试添加到当前日期,而是添加到用户选择的日期
答案 0 :(得分:1)
这里有一个代码剪断我这样做:
一些全局变量:
public int gl_year = -1, gl_month = -1, gl_day = -1;
这是打开日期选择器按钮的定义
datePickerButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (debug)
Log.d(TAG, "datePickerButton.setOnClickListener() ");
new DatePickerDialog(MainActivity.this, dateListener, gl_year,
gl_month, gl_day).show();
}
});
那就是听众
private DatePickerDialog.OnDateSetListener dateListener = new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
int displMonth = monthOfYear + 1;
if (debug)
Log.d(TAG, "onDateSet() " + year + "/" + displMonth + "/"
+ dayOfMonth);
Calendar selectedDate = null;
selectedDate = Calendar.getInstance();
gl_year = year;
gl_month = monthOfYear;
gl_day = dayOfMonth;
selectedDate.set(gl_year, gl_month, gl_day);
calendarView.setDate(selectedDate.getTimeInMillis());
}
};
如果你在整数变量gl_day中添加值282,那么在打开日期选择器对话框之前它应该可以正常工作。如果没有将日历对象更改为毫秒时间并添加值24364800000