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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:04:44+00:00 2026-05-24T13:04:44+00:00

I need to refresh TextViews every 5 seconds, I have created TimerTask( and set

  • 0

I need to refresh TextViews every 5 seconds, I have created TimerTask( and set Activity like parameter in contrsuctor) but I got error that I can access widgets only from thread which created them.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.system_data_show);
    currentActivity = this; 
    Timer timer = new Timer();
    timer.schedule(new SystemTimerTask(currentActivity),500, 5000);
    ///////////////// text views from layout /////////////////////////////////////////////
    TextView txtCapture = (TextView) this.findViewById(R.id.txtCapture);
    txtCapture.setText("System Data");
    TextView txtWorkAllowedValue=(TextView)this.findViewById(R.id.workAllowedValue);
    TextView txtBusBroken0Value=(TextView)this.findViewById(R.id.busBroken0Value);
    TextView txtBusBroken1Value=(TextView)this.findViewById(R.id.busBroken1Value);
    TextView txtShortCircuit0Value=(TextView)this.findViewById(R.id.shortCircuit0Value);
    TextView txtShortCircuit1Value=(TextView)this.findViewById(R.id.shortCircuit1Value);
    TextView txtErrorConfigurationValue=(TextView)this.findViewById(R.id.errorConfigurationValue);
    }

How to refresh this textViews on every 5 seconds ? Is there any way not to extend TimerTask, maybe o implement some interface ( I don’t know which) so my SActivity extends Activity implements thatInterface ?

  • 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-24T13:04:45+00:00Added an answer on May 24, 2026 at 1:04 pm

    What you can do is create an inner AsyncTask class that will do do work in the background (get the data you want to refresh the textview with) and when that work is done in the background you post the result in the onPostExecute(you can update UI textview here) method.

    After you have that AsyncTask inner class you do something in your timer like this every 5 seconds:

    new MyAsyncTask.execute();

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

Sidebar

Related Questions

I have a html file need to refresh every 10 seconds, so I have
I need to refresh a particular page say every 2 mins. But, only the
I need to refresh a php script every ten seconds, it is for a
I have some images from another source that need to refresh from their offsite
New question, but really close to need to refresh page in jquery mobile .
I have created a page index.php with a lot of divs and I need
I've I have a site where I need to refresh several parts of the
I need to refresh the webpage, but in the refresh request I want to
I need to refresh a bunch of EDMX files in my solution. We have
I want an animated picture. But I need a refresh-function because plt.show() always opens

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.