Last active
November 10, 2021 13:09
-
-
Save bobekos/4f83599e78333f0da321584991b8cc97 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private TextView textViewStartDate; | |
private String startDate = ""; | |
private String endDate = ""; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_create_wallet); | |
textViewStartDate = findViewById(R.id.text_view_startDate); | |
findViewById(R.id.buttonPickStartDate).setOnClickListener(view -> showStartDatePickerDialog(getStartDateListener())); | |
} | |
public void showDatePickerDialog(DatePickerDialog.OnDateSetListener listener){ | |
DatePickerDialog startDatePickerDialog = new DatePickerDialog( | |
this, | |
listener, | |
Calendar.getInstance().get(Calendar.YEAR), | |
Calendar.getInstance().get(Calendar.MONTH), | |
Calendar.getInstance().get(Calendar.DAY_OF_MONTH) | |
); | |
star`tDatePickerDialog.show(); | |
} | |
@Override | |
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) { | |
if (startDate.isEmpty()) { | |
startDate = "Day/Month/Year:" +dayOfMonth +"/" + month + "/" +year; | |
textViewStartDate.setText(startDate); | |
showDatePickerDialog(); | |
} else { | |
endDate = "Day/Month/Year:" +dayOfMonth +"/" + month + "/" +year; | |
//create another textview where you can set the endate | |
} | |
} | |
public DatePickerDialog.OnDateSetListener getStartDateListener() { | |
return new DatePickerDialog.OnDateSetListener() { | |
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) { | |
boolean showEndPicker = startDate.isEmpty(); | |
startDate = "Day/Month/Year:" +dayOfMonth +"/" + month + "/" +year; | |
textViewStartDate.setText(startDate); | |
//show end picker only when start date is set first time | |
if (showEndPicker) { | |
showDatePickerDialog(getEndDateListener()); | |
} | |
} | |
}; | |
} | |
public DatePickerDialog.OnDateSetListener getEndDateListener() { | |
return new DatePickerDialog.OnDateSetListener() { | |
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) { | |
endDate = "Day/Month/Year:" +dayOfMonth +"/" + month + "/" +year; | |
textViewEndDate.setText(startDate); | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment