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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:06:51+00:00 2026-06-11T18:06:51+00:00

I wanted to implement a method picking a time and returning it, something like

  • 0

I wanted to implement a method picking a time and returning it, something like

public static int pickTime(Context context, int minuteOfDay) {
    final int[] result = {-1};
    final OnTimeSetListener listener = new OnTimeSetListener() {
        @Override
        public void onTimeSet(TimePicker timePicker, int hourOfDay, int minute) {
            result[0] = 60*hourOfDay + minute;
        }
    };
    new MyTimePickerDialog(context, listener, minuteOfDay/60, minuteOfDay%60, false).show();
    return result[0];
}

only to find out that the dialog returns immediately, and thus my method always return -1.

That’s something I can live with, however, I’m curious if something like this is possible. I don’t care if the app works while waiting for the input, as the TimePicker takes nearly the whole screen anyway.

Note that the standard solution works for me, but I consider this to be a good an exercise for better understanding of the system.

  • 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-11T18:06:53+00:00Added an answer on June 11, 2026 at 6:06 pm

    It’s easily possible from another thread, just wait for the dialog to close. From the main Thread waiting doesn’t work, as it blocks the events processing. So instead of waiting I’d have to run the event loop myself, which might be complicated or even impossible.

    What could be done is passing a TextView, which should be set. However, I always need to do more, so it’s quite useless. I ended up with a class which can be used as follows (invoking the constructor does the whole work):

    new MyTimePickerCallback(context, oldMinutes) {
        @Override
        public void onResult(int newMinutes) {
            ... do whatever you want
        }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wanted to understand how we can implement a safe logout method in a
I wanted to implement a Node type like written below but I want to
I always wanted to implement swypable tabs in my application, like the ones in
I'd like to implement a function with both generics and varargs. public class Question
1) OnCreate is public method of instantiated object from ClsLast class. But I wanted
I wanted to implement an algorithm with Dictionary<Dictionary<char,int>, List<string>> to find the anagram words
I'm hoping to implement something like all of the great plugins out there for
I wanted to implement a method in a abstract class that is called by
I wanted to implement a default sort order in my domain class and immediately
I wanted to implement a search feature for my web app. I choose Haystack

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.