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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:49:26+00:00 2026-05-30T14:49:26+00:00

I have a layout where I placed a TimePicker and two buttons for select

  • 0

I have a layout where I placed a TimePicker and two buttons for select time:

    <?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/time_picker"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
        />
    <LinearLayout android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:orientation="horizontal"
        >
    <Button android:id="@+id/time_picker_ok"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/yes"
            android:onClick="set"/>
    <Button android:id="@+id/time_picker_cancel"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/no"
            android:onClick="cancel"/>
    </LinearLayout>
    </LinearLayout>

I call it through method from another activity:

public void showPicker(View view) {
    LayoutInflater li = LayoutInflater.from(this);
    View dialogView = li.inflate(R.layout.time_picker, null);
    dialogView = new TimePicker(this);

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.time_start_label);
    builder.setView(dialogView);

    ad = builder.create();
    ad.show();
}

And I have a handler for “yes” button:

public void set(View view) {
    LayoutInflater li = LayoutInflater.from(this);
    LinearLayout ll = (LinearLayout) li.inflate(R.layout.time_picker, null);
    TimePicker tp = (TimePicker) ll.findViewById(R.id.time_picker);
    int hour = tp.getCurrentHour();
    int minute = tp.getCurrentMinute();

    Utils.showMessage(this, hour + " " + minute); // Toast message
}

But when I click on @+id/time_picker_ok I get a current system time instead of a selected time.

How can I get selected time?

  • 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-30T14:49:27+00:00Added an answer on May 30, 2026 at 2:49 pm

    getCurrentXXX() is supposed to answer the current hour or minute.

    To read the time entered by the user, you have to use a listener like this:

    // the callback received when the user "sets" the time in the dialog
    private TimePickerDialog.OnTimeSetListener mTimeSetListener =
        new TimePickerDialog.OnTimeSetListener() {
            public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                mHour = hourOfDay;
                mMinute = minute;
                updateDisplay();
            }
        };
    

    See this tutorial for more details: http://developer.android.com/resources/tutorials/views/hello-timepicker.html

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

Sidebar

Related Questions

I have a layout defined in XML. It contains also: <RelativeLayout android:id=@+id/item android:layout_width=fill_parent android:layout_height=wrap_content
I have one ImageButton in my xml layout like that : <ImageButton android:id=@+id/tabsButton android:background=@drawable/button
I have two layouts xml and can't get the second layout to work correctly.
I am creating a xml layout for android in which I have a imageview
I have a FrameLayout in which I have placed two identical TextViews. I want
I have a HorizontalFieldManager with two buttons inside it. The buttons need to be
I am creating a layout,I have total 10 textviews placed vertically.On th e left
I have 4 ImageButton in a linearlayout placed equally distanced. For now I am
I have created a block and I have placed it in to the layout
I have a submenu placed in my layout wich differs from controller to controller,

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.