I have a DatePicker in my app, i’m using this code to retrieve its values:
DatePicker d= (DatePicker) findViewById(R.id.datePicker1);
int day = d.getDayOfMonth();
int month = d.getMonth() + 1;
int year = d.getYear();
final String x=String.valueOf(day);
final String y=String.valueOf(month);
final String z=String.valueOf(year);
Button button1= (Button) (findViewById(R.id.button1));
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(SNCFTActivity.this, x+" " +y+ " "+z, Toast.LENGTH_LONG).show();
However, when tapping on button i always have the current date that is retrieved/displayed in Toast, not the values set in DatePicker.
Can you please to help me out solving that problem?
Thank you very much.
use these inside your
onClickfunction