How to get date from date picker in android?
android, datepicker
Solution
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
tvDisplayDate.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);
}
};
Refer Thsi link..May be this will help you.:- http://www.mkyong.com/android/android-date-picker-example/
Problem
I am using the `DatePicker` for my application. I want to get the date that I have selected (on the `DatePicker`), but it's not returning the selected date. It's always returning the current date. How can I get the selected date from `DatePicker`? Any help will be appreciated. ``` day = pickDate.getDayOfMonth(); month = pickDate.getMonth() + 1; year = pickDate.getYear(); readAndChoose = (Button) findViewById(R.id.btnReadAndChoose); readAndChoose.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Context context = getApplicationContext(); CharSequence text = "" + day + "-" + "" + month + "-" + "" + year; int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(context, text, duration); toast.show(); /* * Intent i = new Intent(BirthActivity.this, * CompassActivity.class); startActivity(i); */ } }); ``` I don't want create a `DatePicker` dialog but I want to use the DatePicker provided by Android.