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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:33:38+00:00 2026-06-04T07:33:38+00:00

I have a timePicker dialog, which ca be called from different buttons. How can

  • 0

I have a timePicker dialog, which ca be called from different buttons.
How can I pass the Id from which the dialog is called?

This is the relevant Code:

    //Time picker
    private int pHour;
    private int pMinute;
    static final int TIME_DIALOG_ID = 0;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        /** Get the current time */
        final Calendar cal = Calendar.getInstance();
        pHour = cal.get(Calendar.HOUR_OF_DAY);
        pMinute = cal.get(Calendar.MINUTE);
}

The click event from the Buttons:

public void onClick(View v) {

 // Here I should pass the v.getId() to the dialog
 showDialog(TIME_DIALOG_ID);
}

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case TIME_DIALOG_ID:
        return new TimePickerDialog(this,
                mTimeSetListener, pHour, pMinute, false);
    }
    return null;
}

/** Callback received when the user "picks" a time in the dialog */
private TimePickerDialog.OnTimeSetListener mTimeSetListener =
    new TimePickerDialog.OnTimeSetListener() {
        public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
            pHour = hourOfDay;
            pMinute = minute;
            //Here I should know from which v.getId() the dialog was called
        }
    };

Thanks!

  • 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-04T07:33:39+00:00Added an answer on June 4, 2026 at 7:33 am

    You will have to write your own picker for what you want to do:

    Assuming that you have to call the same picker for all buttons, I suggest you to use, switch statement on the Button‘s

     public void onClick(View v) {
    
      switch(v.getId()){
    
      case R.id.Button1:
           showDialog(TIME_DIALOG_ID);
           break;
    
      case R.id.Button2: 
           showDialog(TIME_DIALOG_ID);
           break;
      }
    }
    

    You can use different Dialog ID’s in case you want different Dialog‘s to pop up.

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

Sidebar

Related Questions

I have time picker in my app. I'm showing timePicker.date and the time is
i have this code for a datetime picker <link type=text/css href=css/ui-lightness/jquery-ui-1.7.2.custom.css rel=stylesheet /> <script
I have a timepicker class and can show the time after picked. My question
I have a jQuery Timepicker code below: $('#timepicker').timepicker({ showOn: 'button', button: '.timepicker_button_trigger' }); This
I have a widget which is a TimePicker that retrieves the time saved in
I have written a code to integrate timepicker with editable which is being used
Hello I am using two buttons which on click show date picker dialog and
I have this code in my view (JS): $(#mydivelement).timepicker(); Instead of only timepicker, it
I have a DatePicker and a TimePicker in my app. Can anyone tell me
Does anyone have any example on how to put a date time picker inside

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.