datepicker에서 날짜를 가져와 날짜 수정을 추가하고 텍스트 필드에 표시하는 데 문제가 있습니다.datepicker 대화 상자에서 날짜를 가져와 표시하기 전에 며칠을 추가하는 방법
두 개의 텍스트 상자와 버튼이 있습니다. 나는 단추에 datepicker 대화 상자를 구현하고 하나의 텍스트 상자에 해당 날짜를 표시하지만 datepicker 날짜에 270 일을 추가하고 textbox2에 새 날짜를 표시하려고합니다. datepicker_date에 270 일을 추가하고 newdate 텍스트 필드에 표시합니다.
이
내 프로그램이 당신의 목적을 위해public void setCurrentDateOnView() {
datepicker_date = (TextView) findViewById(R.id.datepicker);
newdate = (TextView) findViewById(R.id.datepicker1);
//dpResult = (DatePicker) findViewById(R.id.dpResult);
final Calendar c = Calendar.getInstance();
year = c.get(Calendar.YEAR);
month = c.get(Calendar.MONTH);
day = c.get(Calendar.DAY_OF_MONTH);
// set current date into textview
datepicker_date.setText(new StringBuilder()
// Month is 0 based, just add 1
.append(month + 1).append("-").append(day).append("-")
.append(year).append(" "));
// set current date into datepicker
}
public void addListenerOnButton() {
date = (Button) findViewById(R.id.date);
date.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
showDialog(DATE_DIALOG_ID);
}
});
}
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DATE_DIALOG_ID:
// set date picker as current date
return new DatePickerDialog(this, datePickerListener, year, month,
day);
}
return null;
}
private DatePickerDialog.OnDateSetListener datePickerListener = new DatePickerDialog.OnDateSetListener() {
// when dialog box is closed, below method will be called.
public void onDateSet(DatePicker view, int selectedYear,
int selectedMonth, int selectedDay) {
year = selectedYear;
month = selectedMonth;
day = selectedDay;
// set selected date into textview
datepicker_date.setText(new StringBuilder().append(month + 1)
.append("-").append(day).append("-").append(year)
.append(" "));
// set selected date into datepicker also
//dpResult.init(year, month, day, null);
}
};
public void setCurrentDate1OnView() {
newdate = (TextView) findViewById(R.id.datepicker1);
//dpResult = (DatePicker) findViewById(R.id.dpResult);
final Calendar c = Calendar.getInstance();
year1 = c.get(Calendar.YEAR);
month1 = c.get(Calendar.MONTH);
day1 = c.get(Calendar.DAY_OF_MONTH);
// set current date into textview
newdate.setText(new StringBuilder()
// Month is 0 based, just add 1
.append(month1 + 1).append("-").append(day1).append("-")
.append(year1).append(" "));
}