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 6934167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:55:31+00:00 2026-05-27T11:55:31+00:00

I have two date buttons. These two buttons contains a String as text. If

  • 0

I have two date buttons. These two buttons contains a String as text.
If someone clicks on the button a datepicker appears. After this datepicker
I want to check if the two buttons contains the same datestring.
If so, I want to let two buttons appear (below these two buttons) with two
timepickers.

First image when no date is choosen

This is what should happen

The problem is, the method which checks if the two dates are equal, automatically starts at first after clicking the button. So I have to click the button twice to properly check if the dates are equal.

Here’s my code:

First the onClickListeners

startDate.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {

        DateDialog dateStart = new DateDialog(startDate, mYear, mMonth, mDay);
        checkdates();

    }
});

endDate.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        DateDialog dateEnd = new DateDialog(endDate, mYear, mMonth, mDay);
        checkdates();
    }
});

Second, the checkdates method:

private void checkdates() {

    String firstdate = startDate.getText().toString();
    String seconddate = endDate.getText().toString();

    if (firstdate.equals(seconddate)) {
        row1.setVisibility(View.VISIBLE);
        row2.setVisibility(View.VISIBLE);
    } else {
        row1.setVisibility(View.INVISIBLE);
        row2.setVisibility(View.INVISIBLE);
    }
}

And at last, the Class DateDialog which is called in the onClickListener:

public class DateDialog {

private int mMonth;
private int mYear;
private int mDay;
private Button txtButton;

public DateDialog(Button b, int year, int month, int day){
    txtButton = b;
    onCreateDialog(year, month, day);
}

protected Dialog onCreateDialog(int year, int month, int day) {
        DatePickerDialog dialog = new DatePickerDialog(NostradamusActivity2.parentcontext, mDateSetListener, year,
                month, day);
        dialog.show();
        return null;
}

// updates the date we display in the TextView
private void updateDisplay() {
    txtButton.setText(new StringBuilder()
            // Month is 0 based so add 1
            .append(mYear).append("-").append(mMonth + 1).append("-")
            .append(mDay).append(""));
}

private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() {
    public void onDateSet(DatePicker view, int year, int monthOfYear,
            int dayOfMonth) {
        mYear = year;
        mMonth = monthOfYear;
        mDay = dayOfMonth;
        updateDisplay();
    }
};
 }
  • 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-05-27T11:55:32+00:00Added an answer on May 27, 2026 at 11:55 am

    You can define an interface inside DateDialog class like this:

    public static interface DateDialogListener
    {
         public void dialogDateChanged();
    }
    

    and declare a field inside DateDialog class as

    DateDialogListener dateListener;
    

    and create a setter method for it also.

    and in updateDisplay() put this call at the end also

    if(dateListener != null)
    dateListener.dialogDateChanged();
    

    and when you open a dialog from button onClick() inside Activity use DateDialogListener like this way:

    DateDialog dateStart = new DateDialog(startDate, mYear, mMonth,mDay);
    dateStart.setDateListener( new DateDialogListener()
    {
         public void dialogDateChanged()
         {
             checkdates(); 
         }     
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the jQuery datepicker where I have two textboxes (start date / end
I have two csv file. First File has date offerid clicks orders Second File
Overview: I have two text boxes at the top of this form for inputting
I have two tables: who contains these fields: gmdc_employee file_id company_id employee_id employee_name file_description
I have two buttons on my web form. When clicking on the first button,
I have two date entities, start_date and end_date and now I want to find
I have two Zend Date objects to work with: $now = Zend_Date::now(); $sessionStart =
I have two Java instances of java.util.Date and I have to find out if
I have two tables: Client(id,name,...) Purchase(id,item,date,client_id,...) They have their respective Model, with their validations.
I have two dates: how do I compare which one is greater date 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.