2 つの別々の編集テキスト ボックスに入る 2 つの日付ピッカーがあります。1つは出発日、もう1つは帰国日です。帰国日が出発日より後でなければならないことを確認する検証理論が必要です..
助けてくれてありがとう
これが私のコードです:
DepartDate = (TextView) findViewById(R.id.editText1);
ReturnDate = (TextView) findViewById(R.id.editText2);
public void selectDate(View view) { // Function used to set the date
switch(view.getId()) {
case R.id.imageButton1: // Using the first image button to call the first date picker.
DialogFragment newFragment1 = new SelectDateFragment(0); // Giving an index to the date picker so it won't overwrite the textfields
newFragment1.show(getSupportFragmentManager(), "DatePicker");
break;
case R.id.imageButton2: // Using the first image button to call the first date picker.
DialogFragment newFragment2 = new SelectDateFragment(1); // Giving an index to the date picker so it won't overwrite the textfields
newFragment2.show(getSupportFragmentManager(), "DatePicker");
break;
}
}
public void populateSetDate(int year, int month, int day) { // Setting the format of the date and setting where the selected date will be entered to
DepartDate = (TextView) findViewById(R.id.editText1);
DepartDate.setText(month + "/" + day + "/" + year); //Setting the format in which the date will be shown in the textview
}
public void populateSetDate1(int year1, int month1, int day1) {
ReturnDate = (TextView) findViewById(R.id.editText2);
ReturnDate.setText(month1 + "/" + day1 + "/" + year1);
}
public class SelectDateFragment extends DialogFragment implements
DatePickerDialog.OnDateSetListener {
int type;
public SelectDateFragment(int type) {
this.type = type;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Calendar calendar = Calendar.getInstance();
int yy = calendar.get(Calendar.YEAR);
int mm = calendar.get(Calendar.MONTH);
int dd = calendar.get(Calendar.DAY_OF_MONTH);
return new DatePickerDialog(getActivity(), this, yy, mm, dd);
}
public void onDateSet(DatePicker view, int yy, int mm, int dd) {
if(type == 0) { //If the first date picker was clicked then call the following function
populateSetDate(yy, mm + 1, dd);
} else if(type == 1) { //If the second date picker was clicked then call the following function
populateSetDate1(yy, mm + 1, dd);
}
}
onClickListener を持つボタンもあります。帰国日が出発日より後の場合、ボタンをクリックできないようにしたいと考えています。