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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:53:22+00:00 2026-05-24T06:53:22+00:00

I have a custom view that contains several views in itself. I’ve made it

  • 0

I have a custom view that contains several views in itself. I’ve made it so that when one of the views inside this container view is clicked, it will run a “timer” thread that needs to update the a TextView, also inside the container view, every second. My problem occurs when I want to update the TextView every second. Apparently, it wasn’t as easy as I had thought. I implemented Runnable inside my container view like so, and executed the thread when the button was clicked to start the timer:

public void run() {
        while(runnning) {
            // if one second has passed, update the Textview
        }
}

I get the typical cannot-touch-views-outside-hierarchy exception, which basically means it’s not running on the UI thread. I don’t want to use post(Runnable) here because I don’t want to wait all the way till the end of the thread to update one second. It’s also not practical for me to pass the entire Activity it’s in to itself to run runOnUiThread(Runnable). So could someone tell me how I might go about doing this? If anyone needs clarification, please let me know!

  • 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-24T06:53:23+00:00Added an answer on May 24, 2026 at 6:53 am

    You want to use an Android AsyncTask. Its an Android specific construct for just this type of periodic GUI updating while waiting for something to finish.

    Do your timer in doInBackground and have it call publishProgress whenever you want it to update the GUI. Then in onProgressUpdate just update the GUI. onProgressUpdate runs on the GUI thread and doInBackground runs on a background thread automaticially.

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

Sidebar

Related Questions

I have created one custom view that contains the horizontalscrollview. Now when i changes
I have created one custom view that contains the horizontalscrollview. Now when i changes
I have a flex project that is made of up several custom components that
I have an app that contains a custom view, and in it I want
Currently, I have an NSStatusItem that, when clicked, shows a custom view below it.
I have a view that I want to add some custom drawing to. I
I have a view that contains a UITableView and a UILabel which works perfectly
I am writing a custom NSView subclass. I have several instances of this class
I have a controller decorated with an AuthorizeAttribute. The controller contains several actions that
I am generating a custom View that contains a number of drawables that are

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.