I have one TextView and when I touch the TextView it will call the Date and TimePicker. First I'am showing the DatePicker and Once I have selected date then I can set the value. After I set the value I'am getting time from the TimePicker. Like the DatePicker I can give done after I chose the time.
But the values are setting automatically even I touch outside the dialog.
For example after I touch the TextView it calls the DatePicker. Even If i not set the value
This is my code.
dataandtime.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
TimePickerDialog tpd = new TimePickerDialog(context, mTimeSetListener, mhour, mminute, false);
tpd.show();
DatePickerDialog dpd = new DatePickerDialog(context,
mDateSetListener, myear, mmonth, mday);
dpd.show();
}
});
private DatePickerDialog.OnDateSetListener mDateSetListener = new
DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
myear=year;
mmonth=monthOfYear+1;
mday=dayOfMonth;
if(mmonth<10)
{
month = 0 + Integer.toString(mmonth);
}
else
{
month = Integer.toString(mmonth);
}
if(mday<10)
{
day = 0 + Integer.toString(mday);
}
else
{
day = Integer.toString(mday);
}
nextdate = (new StringBuilder().append(myear).append("-").append(month).append("-").append(day).append(" ")).toString();
}
};
private OnTimeSetListener mTimeSetListener = new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
// TODO Auto-generated method stub
mhour = hourOfDay;
mminute = minute;
if(mhour<10)
{
hour = 0 + Integer.toString(mhour);
}
else
{
hour = Integer.toString(mhour);
}
if(mminute<10)
{
tminute = 0 + Integer.toString(mminute);
}
else
{
tminute = Integer.toString(mminute);
}
if(msecond<10)
{
second = 0 + Integer.toString(msecond);
}
else
{
second = Integer.toString(msecond);
}
nexttime = (new StringBuilder().append(hour).append(":").append(tminute).append(":").append(second)).toString();
dateandtime = nextdate+nexttime;
dataandtime.setText(dateandtime);
}
};