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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:08:35+00:00 2026-05-27T08:08:35+00:00

Good afternoon everyone So, I’m trying to dynamically change textview’s properties. basically, I defined

  • 0

Good afternoon everyone

So, I’m trying to dynamically change textview’s properties.
basically, I defined a Duration. and I want to my handler/runnable to append text to a textView until I reach the duration.

public class Dynamic_testActivity extends Activity
{
    public Context      context         = null;
    public TextView     view            = null;
    public Handler      mHandler        = null;
    public long         startTime       = 0L;
    public final int    duration_millis = 10000;

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

        context = getApplicationContext();

        view    = (TextView)    findViewById(R.id.textView1);
        view.append("\n");

        mHandler = new Handler();
    }

    @Override
    protected void onStart() {
        super.onStart();

        startTime = System.currentTimeMillis();

        mHandler.post(new Runnable() {
            @Override
            public void run() {
                view.append("Hell_yeah_!\n");
                // 10 character lenght
            }
        });
    }
}

So yes, it append the text once, because the run do so.
But how could I make some kind of loop, without blocking the UI Thread, and append text until the end of the duration.

That was the first step …

The second part now … In fact, I Want to change the color of the text.
using

Spannable WordtoSpan = new SpannableString(view.getText());        
WordtoSpan.setSpan(new ForegroundColorSpan(Color.BLUE), 0, view.getText().length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

I want to the color changing to be dynamic for the duration … like a karaoke …
So, is it possible to make that in the runnable without having the UI Thread blocked until the end of the duration ? and How ?

If anyone could explain the complet process ? or post some source code


Solved.
Here is a basic example…
There is still a little trouble … at the very beginning of the application, the whole textview is yellow, and after a second, it updates the display as it should be .
If any one knows why, advices are welcome =)

Note : there’s only two simple Textview in the layout… Duration is in milliseconds… and there is 10 character in the dynamic textview to fit the duration … So basically, one char = one second …

public class Dynamic_testActivity extends Activity
{
    public Context      context                                 = null;
    public TextView     view                                    = null;
    public TextView     view2                                   = null;
    public Handler      handler                                 = null;
    public long         start_time, current_time, elapsed_time  = 0L;
    public final int    duration                                = 10000;
    public int          end                                     = 0;

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

        context = getApplicationContext();
        view    = (TextView)    findViewById(R.id.textView1);
        view2   = (TextView)    findViewById(R.id.textView2);
        handler = new Handler();
    }

    @Override
    protected void onStart() {
        super.onStart();

        start_time   = Long.valueOf( System.currentTimeMillis() );
        current_time = start_time;

        handler.postDelayed(new Runnable() {
            @Override
            public void run() {

                current_time = Long.valueOf( System.currentTimeMillis() );
                elapsed_time = Long.valueOf(current_time) - Long.valueOf(start_time);

                if ( elapsed_time >= duration + 30 ) {
                    Toast.makeText(context, "Done", Toast.LENGTH_LONG).show();
                    //finish();
                } else {
                    end = (int) (elapsed_time / 1000);
                    Spannable WordtoSpan = new SpannableString(view.getText());
                    WordtoSpan.setSpan(new ForegroundColorSpan(Color.YELLOW), 0, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

                    view.setText(WordtoSpan);
                    view2.setText("time : " + elapsed_time);
                    handler.postDelayed(this, 10);
                }
            }
        }, 10);
    }
}
  • 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-27T08:08:36+00:00Added an answer on May 27, 2026 at 8:08 am

    In your run() methond, you can call mHandler.post(this) (or use postDelayed to delay it)

    There is property change animation in API level 14, but if you are targetting a lower version, use postDelayed repetively to change progressively the color of the text.

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

Sidebar

Related Questions

Good afternoon everyone! As you may know, many companies that sell SSL certificates offer
good afternoon, I am trying to display a list of items in a table
Good Afternoon, I'm currently trying to build something incredibly simple inside of the Google
Good Afternoon, I am trying to get these results into arrays in PHP so
Good afternoon, We are trying to build a prototype of Memory Mapped File Caching
Good Afternoon, I am trying to use the composite filter but in vain. While
Good afternoon everyone, I am having an issue with a stored procedure inserting an
Good afternoon everyone. I was wondering if there is anyway to have the MVC
Good afternoon Overflowers! ;) What I want to do: I'm interested in verifying transferred
Good afternoon, Wow what a title. Basically here is the thing. If have a

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.