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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:12:23+00:00 2026-06-11T04:12:23+00:00

I want to have in my activity a button that shows default the current

  • 0

I want to have in my activity a button that shows default the current date as a button title and when i click the button to show a date picker dialog and shown the new pick as button title.

How can i achieve that?Any better idea?Is better to do this with EditText for being easier fro the user that he can change the date?

  • 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-11T04:12:25+00:00Added an answer on June 11, 2026 at 4:12 am

    i have attached code here for both time and date, use this as per your requirements.
    here intend of txtdate and txtTime youcan set it on button text.

    private static final int DIALOG_DATE = 1;
             private static final int DIALOG_TIME = 2;    
    
    
    private Calendar dateTime = Calendar.getInstance();
         private SimpleDateFormat dateFormatter = new SimpleDateFormat(
                 "MMMM dd yyyy");
         private SimpleDateFormat timeFormatter = new SimpleDateFormat(
                 "hh:mm a");
    
    
                     txtstdate.setText(dateFormatter.format(dateTime.getTime()));   
      txtAddtime.setText(timeFormatter.format(dateTime.getTime()));
    
    
    @Override
        protected Dialog onCreateDialog(int id)
        {
            switch (id)
            {
            case DIALOG_DATE:
                return new DatePickerDialog(this, new OnDateSetListener()
                {
    
                    @Override
                    public void onDateSet(DatePicker view, int year,
                            int monthOfYear, int dayOfMonth)
                    {
                        dateTime.set(year, monthOfYear, dayOfMonth);
                        txtstdate.setText(dateFormatter.format(dateTime.getTime()));
                        txtAdddate.setText(dateFormatter.format(dateTime.getTime()));
                    }
                }, dateTime.get(Calendar.YEAR),
                   dateTime.get(Calendar.MONTH),
                   dateTime.get(Calendar.DAY_OF_MONTH));
    
            case DIALOG_TIME:
                return new TimePickerDialog(this, new OnTimeSetListener()
                {
    
                    @Override
                    public void onTimeSet(TimePicker view, int hourOfDay,
                            int minute)
                    {
                        dateTime.set(Calendar.HOUR_OF_DAY, hourOfDay);
                        dateTime.set(Calendar.MINUTE, minute);
                        txtsttime.setText(timeFormatter.format(dateTime.getTime()));
                        txtAddtime.setText(timeFormatter.format(dateTime.getTime()));
                    }
                }, dateTime.get(Calendar.HOUR_OF_DAY),
                   dateTime.get(Calendar.MINUTE), false);
    
            }
            return null;
        }
    
    
    }
    
    **Call Dialog:**    
    

    Call This method on button click event.

    showDialog(DIALOG_DATE);
    
    showDialog(DIALOG_TIME);
    

    Visit For More Ref: http://hasmukhbhadani.blogspot.in/search/label/Date%20and%20time%20Dialog.
    http://hasmukhbhadani.blogspot.in/search/label/DatePickerSlider%20in%20android.

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

Sidebar

Related Questions

I want to finish the Activity on Home Button Click . I have below
I have an activity that extends MapActivity. I want to show map inside a
I have a phonegap activity which I want to start via a button press:
I have a database in one activity that I want to open in another
I have a developer eyes-only activity that I don't want end users to reverse
I have a custom dialog in my app that descends from Activity and uses
In an app I have very reused Activity, that shows a list of stuff
Basically I want to have a button to start a new activity after login.
I have a simple code that shows strings in a TextView after a button
in my app i have activity with XML layout, i want to build an

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.