Note that there are some explanatory texts on larger screens.

plurals
  1. POBasic Thread in Android
    primarykey
    data
    text
    <p>Just studying Threads in Android (I'm also a little new to Threads period). I'm looking at various other posts but still need a little clarification. I'm keeping it simple with HelloWorld. What I want to is display the Message: "Hello World this is a thread" with each word displayed at 1 second intervals. Thought use a string array with the message. Then use a for loop in the thread to iterate through each element. I'm pretty sure I understand the logic of my problem - in that the whole loop executes in the delay time frame. Can anyone tell me how I can break this out so I can display each element at 1 second intervals? Here is my code:</p> <pre><code>public class HelloWorld extends Activity { Handler m_handler; Runnable m_handlerTask ; private TextView hello; private String[] HelloWorld = { "Hello", "World", "This", "Is", "A", "Thread", }; int i=0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_hello_world); hello = (TextView) findViewById(R.id.hello); m_handler = new Handler(); m_handlerTask = new Runnable() { @Override public void run() { if(i&lt;HelloWorld.length-1) { hello.append(HelloWorld[i]); hello.setText("\n"); i++; } m_handler.postDelayed(m_handlerTask, 1000); } }; m_handlerTask.run(); m_handler.removeCallbacks(m_handlerTask); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.hello_world, menu); return true; } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload