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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:50:53+00:00 2026-05-24T12:50:53+00:00

I am creating a Custom dialog where I want to use both DatePicker and

  • 0

I am creating a Custom dialog where I want to use both DatePicker and TimePicker .Although I am able to use TimePicker as I want but for DatePicker I am short of ideas.
Please Help Me.
My Code is as follows

My XML Layout file is…

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TimePicker android:id="@+id/timePicker1"
    android:layout_width="wrap_content" android:layout_height="wrap_content"></TimePicker>
<DatePicker android:id="@+id/datePicker1"
    android:layout_width="wrap_content" android:layout_height="wrap_content"></DatePicker>
<Button android:id="@+id/buttondatetime" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:text="OK" />

And My Java Code for Creating Custom Dialog is

void dialogDateTime()
{
    dialog = new Dialog(this);
    dialog.setContentView(R.layout.datetime);
    dialog.setCancelable(true);
    dialog.setTitle("This is Dialog 1");
    dialog.show();

    TimePicker time_picker = (TimePicker) dialog.findViewById(R.id.timePicker1);
    time_picker.setOnTimeChangedListener(new OnTimeChangedListener()
    {
        @Override
        public void onTimeChanged(TimePicker view, int hourOfDay, int minutes)
        {
            // TODO Auto-generated method stub

        }
    });

    DatePicker date_picker = (DatePicker) dialog.findViewById(R.id.datePicker1);




    Button btn_ok = (Button) dialog.findViewById(R.id.buttondatetime);
    btn_ok.setOnClickListener(new OnClickListener()
    {

        @Override
        public void onClick(View v)
        {
            // TODO Auto-generated method stub
            String text = "Time "+hours+":"+minute;
            tv_date_time.setText(text);
            dialog.cancel();
        }
    });

}

@Override
protected Dialog onCreateDialog(int id)
{
// TODO Auto-generated method stub

    switch (id) 
    {
    case DIALOG_1:
        dialogDateTime();
        break;
    case DIALOG_2:
        dialogTwo();
        break;
    default:
        break;
    }
    return super.onCreateDialog(id);
}

I am not getting any method for DatePicker as in TimePicker So I am not able to use DatePicker
Please Help

  • 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-24T12:50:54+00:00Added an answer on May 24, 2026 at 12:50 pm

    Thanks for not replying I found answer on my own ..
    I changed my method like this

    void dialogDateTime()
    {
        dialog = new Dialog(this);
        dialog.setContentView(R.layout.datetime);
        dialog.setCancelable(true);
        dialog.setTitle("This is Dialog 1");
        dialog.show();
    
        TimePicker time_picker = (TimePicker) dialog.findViewById(R.id.timePicker1);
        time_picker.setOnTimeChangedListener(new OnTimeChangedListener()
        {
            @Override
            public void onTimeChanged(TimePicker view, int hourOfDay, int minutes)
            {
                // TODO Auto-generated method stub
                // Toast.makeText(CustomDialog.this,
                // "hourOfDay = "+hourOfDay+"minute = "+minute , 1000).show();
                hours = hourOfDay;
                minute = minutes;
            }
        });
    
        final DatePicker date_picker = (DatePicker) dialog.findViewById(R.id.datePicker1);
        Button btn = (Button) dialog.findViewById(R.id.buttondatetime);
        btn.setOnClickListener(new OnClickListener()
        {
    
            public void onClick(View arg0)
            {
                // TODO Auto-generated method stub
    
                TextView txt = (TextView) findViewById(R.id.textView1);
                txt.setText("You selected " + date_picker.getDayOfMonth() + "/" + (date_picker.getMonth() + 1) + "/"
                        + date_picker.getYear());
                txt.append("Time "+ hours + ":" +minute);
    
                dialog.cancel();
            }
    
        }
    
        );
    
    }
    

    Thanks to link Android Date and Time Controls

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

Sidebar

Related Questions

I have a problem creating a custom dialog. But I don't find the failure.
I am creating custom html helper for my datepicker. i want to pass inside
I am creating a custom wxPython dialog by subclassing wx.Dialog . When I press
I'm looking for a tutorial that explains creating custom usercontrols in WPF. I want
I found all things working with alert box,dialog box but when i try creating
I want to create a custom callout bubble on MKMapView. But I want to
I'm creating a custom dialog with a background image which has rounded corners. I
I am creating a custom dialog in my app and it looks fine in
At the moment, whenever I need a custom dialog, however simple, I use Delphi's
I'm creating custom window title. I did it with requestWindowFeature and setFeatureInt but not

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.