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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:58:01+00:00 2026-06-10T17:58:01+00:00

I’m currently developing an android application. It needs to update a textview value periodically.

  • 0

I’m currently developing an android application. It needs to update a textview value periodically.

For instance, I want to increase the value by 10 each second.
I tried with the following code, but it is not working fine : the textview is only updated after the increment is finished

package com.example.stack1;

import android.os.Bundle;
import android.app.Activity;
import android.widget.TextView;

public class MainActivity extends Activity{
 /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

    }
    public void onResume(){
        super.onResume();
        TextView output=(TextView) findViewById(R.id.output);
        output.setText(String.valueOf(0));
        System.out.println(0);
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        output.setText(String.valueOf(10));
        System.out.println(10);
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        output.setText(String.valueOf(20));
        System.out.println(20);
    }
}

output is a textview in main.xml file. This file only contains this object.

Note- Expected output in textview is “0”, after 10 second “10” after 20 seconds “20”. However, with this code, the output is blank until 20 seconds , then “20” appears.

  • 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-10T17:58:02+00:00Added an answer on June 10, 2026 at 5:58 pm

    You’ll probably want to use something like AlarmManager instead of sleep() as sleep() will stop everything going on in the process during the sleep time.

    The reason it’s not showing anything is that you’re doing it in the onResume() method. So when it loads up the display, before it actually shows anything, it’s processing that method to get things set up for the user.

    So, what you want is:

    1. Load display with value 0
    2. Wait 10 seconds
    3. Increment and display to user
    4. Wait 10 seconds
    5. Increment and display to user

    What you’re getting because of the sleep() commands is:

    1. Set value to 0
    2. Wait 10 seconds
    3. Set value to 10
    4. Wait 10 seconds
    5. Set value to 20
    6. Display value

    With an AlarmManager, you initialise that in your onResume() method, the display loads, then the AlarmManager increments the value every ten seconds.

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

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I want to show the soap response to UIWebview.. my soap response is, <p><img
I'm trying to select an H1 element which is the second-child in its group
I am currently running into a problem where an element is coming back from

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.