Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8272523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:08:52+00:00 2026-06-08T07:08:52+00:00

The problem that am facing is with the from-to date and time dialog’s. I

  • 0

The problem that am facing is with the from-to date and time dialog’s. I have created all of them separate.
On onCreate i have set the current date and time on the dialog’s for the user. i.e for eg 24/7/2012 as todays date. When ever i change/click on the dialog for the from_date to the date for eg: 26/7/2012 then i have change the text of the to_date dialog to 26/7/2012 via setText. The issue that comes here is when i open the to_date dialog the date that appears in the dialog is 24/7/2012 and not 26/7/2012. How can this be achieved same for date and time picker dialog. I have attached the code below.
Thanks in advance.

public Dialog onCreateDialog(int id) {
    switch (id) {
    case DATE_DIALOG_ID_FROM:
        Log.i("Date Case", "" + from_day);
        return new DatePickerDialog(this, dateListenerfrom, from_year,
                from_month, from_day);
    case DATE_DIALOG_ID_TO:
        Log.i("Date Case", "" + to_day);
        return new DatePickerDialog(this, dateListenerto, to_year,
                to_month, to_day);
    case TIME_DIALOG_ID_FROM:
        return new TimePickerDialog(this, timeListenerfrom, from_hours,
                from_min, false);
    case TIME_DIALOG_ID_TO:
        return new TimePickerDialog(this, timeListenerto, to_hours, to_min,
                false);

    }
    return null;

}

private DatePickerDialog.OnDateSetListener dateListenerfrom = new DatePickerDialog.OnDateSetListener() {

    public void onDateSet(DatePicker view, int yr, int monthOfYear,
            int dayOfMonth) {
        // TODO Auto-generated method stub

        from_year = yr;
        from_month = monthOfYear;
        from_day = dayOfMonth;
        // to_year = yr;
        // to_month = monthOfYear;
        to_day = dayOfMonth;

        Log.i("From Day", "" + from_day);
        Log.i("To Day", "" + to_day);
        Log.i("To Cons", "" + dayOfMonth);

        try {
            updateDateFrom();
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }
};

private DatePickerDialog.OnCancelListener mDateFromCancelListener = new DatePickerDialog.OnCancelListener() {
    public void onCancel(DialogInterface dialog) {

    }
};

private DatePickerDialog.OnDateSetListener dateListenerto = new DatePickerDialog.OnDateSetListener() {

    public void onDateSet(DatePicker view, int yr, int monthOfYear,
            int dayOfMonth) {
        // TODO Auto-generated method stub
        to_year = yr;
        to_month = monthOfYear;
        to_day = dayOfMonth;

        Log.i("From Day", "" + from_day);
        Log.i("To Day", "" + to_day);
        Log.i("To Cons", "" + dayOfMonth);

        try {
            updateDateTo();
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }
};

private void updateDateFrom() throws ParseException {

    SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm");

    try {
        date_from = dateFormat.parse(from_day + "/" + from_month + "/"
                + from_year + " " + from_hours + ":" + to_min);

    } catch (ParseException e) {
        e.printStackTrace();
    }

    System.out.println("From LONG   " + date_from.getTime());

    from_date_builder = new StringBuilder().append(from_day).append('/')
            .append(from_month + 1).append('/').append(from_year);

    from_date.setText(from_date_builder.toString());

    to_date.setText(new StringBuilder().append(from_day).append('/')
            .append(from_month + 1).append('/').append(from_year));

}

private void updateDateTo() throws ParseException {

    SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm");

    try {
        date_to = dateFormat.parse(to_day + "/" + to_month + "/" + to_year
                + " " + to_hours + ":" + to_min);

    } catch (ParseException e) {
        e.printStackTrace();
    }

    System.out.println("To LONG   " + date_to.getTime());

    if (date_from.getTime() <= date_to.getTime()) {
        to_date_builder = new StringBuilder().append(to_day).append('/')
                .append(to_month + 1).append('/').append(to_year);
        to_date.setText(to_date_builder.toString());
    } else {
        Toast.makeText(this, "Please set proper date", Toast.LENGTH_SHORT)
                .show();
    }

}

private TimePickerDialog.OnTimeSetListener timeListenerfrom = new TimePickerDialog.OnTimeSetListener() {
    public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
        from_hours = hourOfDay;
        from_min = minute;
        try {
            updateTimeFrom();
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
};

private TimePickerDialog.OnTimeSetListener timeListenerto = new TimePickerDialog.OnTimeSetListener() {
    public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
        to_hours = hourOfDay;
        to_min = minute;
        try {
            updateTimeTo();
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
};

private void updateTimeFrom() throws ParseException {

    SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm");

    time_from = dateFormat.parse(from_day + "/" + from_month + "/"
            + from_year + " " + from_hours + ":" + from_min);

    from_time_builder = new StringBuilder().append(from_hours).append(':')
            .append(from_min);

    from_time.setText(from_time_builder.toString());

    to_time.setText(new StringBuilder().append(from_hours).append(':')
            .append(from_min));

}

private void updateTimeTo() throws ParseException {

    SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm");

    time_to = dateFormat.parse(to_day + "/" + to_month + "/" + to_year
            + " " + to_hours + ":" + to_min);

    if (time_from.getTime() <= time_to.getTime()
            && date_from.getTime() <= date_to.getTime()) {

        to_time_builder = new StringBuilder().append(to_hours).append(':')
                .append(to_min);

        to_time.setText(to_time_builder.toString());
    }

    else {
        Toast.makeText(this, "Please set proper date", Toast.LENGTH_SHORT)
                .show();
    }

    System.out.println("Thi is in the time to ");

}

This is onClick
{

if (v == from_date) {
        showDialog(DATE_DIALOG_ID_FROM);
    }

    if (v == to_date) {
        showDialog(DATE_DIALOG_ID_TO);
    }

    if (v == from_time) {
        showDialog(TIME_DIALOG_ID_FROM);
    }
    if (v == to_time) {
        showDialog(TIME_DIALOG_ID_TO);
    }

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T07:08:54+00:00Added an answer on June 8, 2026 at 7:08 am

    You have to implement the Below method in your Activity to update the Date/Time to be shown in the Dialog Box.

    protected void onPrepareDialog(int id, Dialog dialog) {
        switch (id) {
            case DATE_DIALOG_ID_TO:
            case DATE_DIALOG_ID_FROM:
                ((DatePickerDialog) dialog).updateDate(mYear, mMonth, mDay);
                break;
        }
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So here is the problem that I am facing: I have an application that
Im currently facing the problem that when i try to set focus on some
I'm facing a problem that I can summarize as it follows: I have a
I'm facing a problem that drives me crazy, I created a java application using
I'm facing a problem that seems to have no straighforward solution. I'm using java.util.Map
I am facing a design problem that I cannot figure out at all. I
the problem I'm facing is this: I have a textbox for a date range
I am new to TCPDF. The small problem that I am facing is that
I am facing the problem that I cannot properly map my foreign key table
Here i am facing a problem that , i configured the hibernate sessionfactory in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.