Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I build the following Android activity?
    primarykey
    data
    text
    <p>onCreate, MyActivity will display five TextViews. After you touch one of the five TextViews, it will hide three to four TextViews and color one red and one green or just color one green.</p> <p>I can code everything up to here. But how can I pause for a few seconds and then repopulate the five TextViews with new values, unhide them and make them all white?</p> <p>Thanks in advance!</p> <p>NEW EDIT NEW EDIT NEW EDIT</p> <p>I tried a Timer in a new project and can attach the code and make my question less vague.</p> <p>Here is the main.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;TextView android:id="@+id/hello" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>Here is the TestTimer.java</p> <pre><code>package com.somecompany.android.testtimer; import java.util.Timer; import java.util.TimerTask; import android.app.Activity; import android.graphics.Color; import android.os.Bundle; import android.util.Log; import android.widget.TextView; public class TestTimer extends Activity { TextView hello; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); hello = (TextView)findViewById(R.id.hello); hello.setTextColor(Color.rgb(0,255,0)); new Reminder(5); } void resetAndContinue() { Log.d("TESTTIMER", "Start resetAndContinue..."); hello.setTextColor(Color.rgb(255,255,255)); Log.d("TESTTIMER", "End resetAndContinue..."); } class Reminder { Timer timer; public Reminder(int seconds) { timer = new Timer(); timer.schedule(new RemindTask(), seconds*1000); } class RemindTask extends TimerTask { public void run() { Log.d("TESTTIMER", "Ran TagRemindTask"); resetAndContinue(); timer.cancel(); //Terminate the timer thread } } } } </code></pre> <p>The issue is that the Timer executes resetAndContinue and logs two entries, but it doesn't set the TextView color from green to white and it doesn't log anymore</p> <p>07-15 13:08:46.894: DEBUG/TESTTIMER(618): Ran TagRemindTask</p> <p>07-15 13:08:46.894: DEBUG/TESTTIMER(618): Start resetAndContinue...</p> <p>07-15 13:08:47.264: DEBUG/dalvikvm(524): GC freed 202 objects / 8936 bytes in 156ms</p> <p>07-15 13:08:52.224: DEBUG/dalvikvm(210): GC freed 43 objects / 2096 bytes in 85ms</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