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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:45:40+00:00 2026-06-15T13:45:40+00:00

For example when I create this timePicker(below) at 18:00, the timePicker’s timeValue will be

  • 0

For example when I create this timePicker(below) at 18:00, the timePicker’s timeValue will be 06:00. At 19:44->07:44… So it doesn’t move to the correct current hour after switching from AM/PM to 24h mode. How can I change that?
My goal is that the timePicker shows the current time when it was created. Like it does when I use it in AM/PM mode.

TimePicker timePicker = (TimePicker) convertView.findViewById(R.id.time_picker);
timePicker.setIs24HourView(true);

Sry for the bad formulation, hope you can understand my question. Otherwise just ask.

UPDATE:

public class ChooseTimeViewDialog extends AlertDialog {

    protected Context context;


    public ChooseTimeViewDialog(final Context context) {
        super(context);     
        this.context = context;
    }

    public void onCreate(Bundle savedInstanceState) {
        LayoutInflater inflater = this.getLayoutInflater();

        View convertView = inflater.inflate(R.layout.dialog_choose_time_view, null);
        setContentView(convertView);
        setTitle(R.string.title_dialog_choose_time_view);

        final TimePicker taskTimePicker = (TimePicker) convertView.findViewById(R.id.dctv_task_time_picker);
        taskTimePicker.setIs24HourView(true);


        setButton(DialogInterface.BUTTON_POSITIVE, "Choose", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                int hour = taskTimePicker.getCurrentHour();
                int minute = taskTimePicker.getCurrentMinute();

                Calendar cal = new GregorianCalendar();
                cal.set(0, 0, 0, hour, minute, 0);

                ((AddTaskViewActivity) context).setSelectedTime(cal.getTime());
            }
        });
        setButton(DialogInterface.BUTTON_NEUTRAL, "No time", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                ((AddTaskViewActivity) context).setSelectedTime(null);
            }
        });

    }

}

XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TimePicker
        android:id="@+id/dctv_task_time_picker"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />

</RelativeLayout>

After I moved the initialiation to onCreate and used the setContentView(View), the background of the dialog is transparent, it’s fullscreen and has no buttons..why?

  • 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-15T13:45:41+00:00Added an answer on June 15, 2026 at 1:45 pm

    I can use timePicker.setCurrentHour(new Date().getHours()), but that’s not the solution I want. It should be possible to solve it in a better way.

    Looking at the source code, this is a bug that appeared sometime after API 10:

    public void setIs24HourView(Boolean is24HourView) {
        if (mIs24HourView == is24HourView) {
            return;
        }
        mIs24HourView = is24HourView; 
        // cache the current hour since spinner range changes
        int currentHour = getCurrentHour();
        updateHourControl();
        // set value after spinner range is updated
        setCurrentHour(currentHour);
        updateAmPmControl();
    }
    

    The correct order is:

    // cache the current hour since spinner range changes
    int currentHour = getCurrentHour();
    mIs24HourView = is24HourView;
    

    Because getCurrentHour() relies on mIs24HourView to return 1-12 or 0-23…

    But until the source code is updated and deployed, you don’t have much of a choice. You need to call setCurrentHour() after setIs24HourView() yourself.

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

Sidebar

Related Questions

I need to create this url: www.example.com/directory/[state]-financial-planners Where [state] will be different depending on
In this example I create three buttons 'one' 'two' 'three'. When clicked I want
Example: public bool Save(MyObj instance) { if (instance.IsNew) { this.repository.Create(instance); } else { this.repository.Update(instance);
I have this example FactoryGirl.define do @site = FactoryGirl.create(:my_site) factory :user do email {
In this example we have 3 related tables on a SQLite database: CREATE TABLE
In this example, I create a user with no profile , then later on
In this simple example, i want to create a String array populated with each
This example is taken from w3schools . CREATE TABLE Persons ( P_Id int NOT
I am following this example (First comment), How to create a custom ListView with
I am trying to create a slider like this example. pls anyone help me.

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.