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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:11:17+00:00 2026-06-05T09:11:17+00:00

I have dialog button and timepicker created in the same xml code below: <?xml

  • 0

I have dialog button and timepicker created in the same xml code below:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TimePicker
        android:id="@+id/timePicker1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

        <LinearLayout android:id="@+id/LinearLayout02" android:layout_height="wrap_content" android:layout_width="fill_parent">
            <Button android:layout_height="wrap_content" android:id="@+id/dialog_ok" android:text="OK" android:layout_width="fill_parent" android:layout_weight="1"></Button>
            <Button android:layout_height="wrap_content" android:text="Cancel" android:id="@+id/dialog_cancel" android:layout_width="fill_parent" android:layout_weight="1"></Button>
        </LinearLayout>

</LinearLayout>

And then i created dialog in java code and also bring in the dialog and timepicker from xml code as showen below:

public void TimePickerDialog(){
    final Dialog dialog = new Dialog(this);

    dialog.setContentView(R.layout.sign_in_dialog);

/////////////////////updated code////////////////////
  TimePicker timePicker1 = (TimePicker) findViewById(R.id.timePicker1);

   timePicker1.setIs24HourView(true); 
/////////////////////////////////

    dialog.setTitle("Quick Mute");

    //Allow the dialog to be cancelable
    dialog.setCancelable(true);
    // Here we add functionality to our dialog box's content. In this example it's the two buttons
    //reference the button
    Button okButton = (Button) dialog.findViewById(R.id.dialog_ok);
    //Create a click listener
    okButton.setOnClickListener(new OnClickListener() {
         //override the onClick function to do something
         public void onClick(View v) {

         }
    });

    //reference the button
    Button cancelButton = (Button) dialog.findViewById(R.id.dialog_cancel);
    //Create a click listener
    cancelButton.setOnClickListener(new OnClickListener() {
         //override the onClick function to do something
         public void onClick(View v) {
          //Close the dialog</span>
                  dialog.dismiss();
        }
    });
    //finally show the dialog   
    dialog.show();
}

The problem i have is how do i get access to the timepicker that was created in xml code so that i can make the timepicker 24 hour timepicker? … and also how do i get the time from the timepicker that is in xml code?

  • 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-05T09:11:18+00:00Added an answer on June 5, 2026 at 9:11 am

    Just like its usually done:

    TimePicker timePicker = (TimePicker)dialog.findViewById(R.id.timePicker1);
    

    and as usual this only works after dialog.setContentView is called. Then, to get the time picked, call:

    timePicker.getCurrentHour();
    timePicker.getCurrentMinute();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a button that opens a dialog when clicked. The dialog displays a
I have a datagrid column with a button that opens a modal dialog box
I have a button, on click of which i display a multi-select dialog. I
I have created a Dialog with two buttons Yes, No, and then I have
In the dialog form below, I have 2 buttons: Save & Cancel. When user
I have dialog created like this $('#add_error').click(function(e) { $('<div>') .load('/someaction/format/html/') .dialog({ title: 'Some title',
I have a dialog form and when I open it I have the button
I have a timePicker dialog, which ca be called from different buttons. How can
I have a custom dialog with an EditText and Button in it. In my
I want to use only the chooser dialog (shown below) from the TimePicker control

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.