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

  • Home
  • SEARCH
  • 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 7026265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:05:40+00:00 2026-05-28T00:05:40+00:00

I’m trying to get selected dates using two date and time picker (like fromdate

  • 0

I’m trying to get selected dates using two date and time picker (like fromdate and To date). If I select fromdate I can get the fromdate to the textview. But if I select second datepicker (todate) update same textview (Fromdate textview).

      public class F2Activity extends InfosoftActivity 

      {
  private int mYear;
  private int mMonth;
  private int mDay;
  private int mYear2;
  private int mMonth2;
  private int mDay2;
  private TextView mDateDisplay;
  private TextView mDateDisplay2;
  private Button mPickDate;
  private Button mPickDate2;
  static final int DATE_DIALOG_ID = 0;
  static final int DATE_DIALOG_IDD = 0;
            public String AAA;
            public String BBB;



    public void onCreate(Bundle savedInstanceState) 
    {
    super.onCreate(savedInstanceState);
    setTheme(android.R.style.Theme_Black);

    setContentView(R.layout.activity_f2);

    Button BtnView=(Button) findViewById(R.id.BtnView);
    Button BtnDownload=(Button) findViewById(R.id.BtnDownload);

        mDateDisplay = (TextView) findViewById(R.id.showMyDate); 
        mDateDisplay2 = (TextView) findViewById(R.id.showMyDatee); 

        mPickDate = (Button) findViewById(R.id.myDatePickerButton);
        mPickDate2 = (Button) findViewById(R.id.myDatePickerButton2);



        mPickDate.setOnClickListener(new View.OnClickListener() 
        {
            public void onClick(View v) {
                showDialog(DATE_DIALOG_ID);
            }
        });

        // get the current date
        final Calendar c = Calendar.getInstance();
        mYear = c.get(Calendar.YEAR);
        mMonth = c.get(Calendar.MONTH);
        mDay = c.get(Calendar.DAY_OF_MONTH);

        // display the current date
        updateDisplay();



        mPickDate2.setOnClickListener(new View.OnClickListener() 
        {
            public void onClick(View v) {
                showDialog(DATE_DIALOG_IDD);
            }
        });


        // get the current date
        final Calendar c2 = Calendar.getInstance();
        mYear2 = c2.get(Calendar.YEAR);
        mMonth2 = c2.get(Calendar.MONTH);
        mDay2 = c2.get(Calendar.DAY_OF_MONTH);

        // display the current date
        updateDisplayTo();

            private void updateDisplay() 

            {
            this.mDateDisplay.setText(new StringBuilder()
                // Month is 0 based so add 1
            .append(mMonth + 1).append("-")
            .append(mDay).append("-")
            .append(mYear).append(" "));

            }
         private void updateDisplayTo() 
         {
        this.mDateDisplay2.setText(
        new StringBuilder()
                // Month is 0 based so add 1
            .append(mMonth2 + 1).append("-")
            .append(mDay2).append("-")
            .append(mYear2).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();

            }
        };

            @Override
            protected Dialog onCreateDialog(int id) {
            switch (id) {
            case DATE_DIALOG_ID:
            return new DatePickerDialog(this,
                        mDateSetListener,
                        mYear, mMonth, mDay);
           }
           return null;
                    }   



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

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

                      mYear2 = year;
                      mMonth2 = monthOfYear;
                      mDay2 = dayOfMonth;
                      updateDisplayTo();

                }
            };        



             protected Dialog onCreateDialog2 (int id)

                       {
                      switch (id)

                      {
                       case DATE_DIALOG_IDD:
                       return new DatePickerDialog(this,
                               mDateSetListener2,
                                  mYear2, mMonth2, mDay2);
                      }

                        return null;
                       }                        

                                           }
  • 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-28T00:05:41+00:00Added an answer on May 28, 2026 at 12:05 am

    If you want to display more than one time of date using DatePicker in your application then no need to use two time DATE_DIALOG_ID. You can use only one and fulfill your requirements. I posted here code I hope it will helps you.

    In button click

    btnFromDate.setOnClickListener(clkListener);
    btnToDate.setOnClickListener(clkListener);
    

    Then

    public OnClickListener clkListener = new OnClickListener()
        {
            @Override
            public void onClick(View v) 
            {
                if(v == btnFromDate)
                {
                    showDateDialog(editTextFromDate, Calendar.getInstance());
                }
                if(v == btnToDate)
                {
                    showDateDialog(editTextToDate, Calendar.getInstance());
                }
                    }
       };
    

    Then

    EditText activeDateDisplay ;
    Calendar activeDate;
    
    public void showDateDialog(EditText dateDisplay, Calendar date) 
        {
            activeDateDisplay = dateDisplay;
            activeDate = date;
            showDialog(DATE_DIALOG_ID);
        }
    

    Then

     CharSequence strFormate_Date;
     int DATE_DIALOG_ID = 0;
    
    @Override
        protected Dialog onCreateDialog(int id) 
        {
            switch (id) 
            {
                case DATE_DIALOG_ID:
                {
                    return new DatePickerDialog(Activity.this, mDateSetListener, activeDate.get(Calendar.YEAR), activeDate.get(Calendar.MONTH), activeDate.get(Calendar.DAY_OF_MONTH));
                }
            }
            return null;
        }
    
        private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() 
        {
            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) 
            {
                activeDate.set(Calendar.YEAR, year);
                activeDate.set(Calendar.MONTH, monthOfYear);
                activeDate.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                updateDisplay(activeDateDisplay, activeDate);
                unregisterDateDisplay();
            }
        };
        private void unregisterDateDisplay() 
        {
            activeDateDisplay = null;
            activeDate = null;
            strFormate_Date = null;
        }
    
        private void updateDisplay(EditText dateDisplay, Calendar date) 
        {
            Time chosenDate = new Time();
            chosenDate.set(date.get(Calendar.DAY_OF_MONTH), date.get(Calendar.MONTH), date.get(Calendar.YEAR));
            long dtDob = chosenDate.toMillis(true);
            strFormate_Date = DateFormat.format("dd/MM/yyyy", dtDob);
            dateDisplay.setText(""+strFormate_Date);
        }
    

    I hope it will solve your problem. If you have any problem regarding this then you can ask me.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.