infm
infm

Reputation: 52

How to continuously update textView with a different delay parameter

I'm pretty new to Java and Android, and now I'm coding some application, which takes a text from ACTION.SEND and display it word by word in a TextView.

I have a method, which returns Spanned text, and I want to continuously update it in my TextView and implement some actions, such as pause or resume. I've already implemented the activity using this guide, but when I simply iterate over the list of words like this:

for (int i = 0; i < listSize; ++i){
   ((TextView) layout.findViewById(R.id.textView).setText(someText);
   Thread.sleep(1000 * coefficient);
}

the application shows only the last element of the array(when the cycle is finished). Could you advise some technique to implement this properly?

Upvotes: 0

Views: 118

Answers (1)

RaphMclee
RaphMclee

Reputation: 1623

The Problem is that you'er blocking the UI-Thread with your sleep method. Try using a Handler (link to doc) and its method postDelayed (here).

Upvotes: 3

Related Questions