I assume I must be doing some very simple thing incorrectly. Is there some reason why my text view won't refresh?
Using java Syntax Highlighting
- import stuff here
- public class ClockActivity extends Activity
- {
- long start_time = System.currentTimeMillis();
- TextView text_timer = null;
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.dttb_activity);
- start_time = System.currentTimeMillis();
- text_timer = (TextView) findViewById(R.id.text_timer);
- Timer timer = new Timer();
- TimerTask task = new TimerTask()
- {
- public void run()
- {
- updateClock();
- }
- };
- timer.scheduleAtFixedRate(task, 0, 1000);
- }
- public void updateClock()
- {
- long current_time = System.currentTimeMillis();
- long elapsed_time = current_time - start_time;
- Date elapsed = new Date(elapsed_time);
- int hours = elapsed.getHours();
- int minutes = elapsed.getMinutes();
- int seconds = elapsed.getSeconds();
- String message = String.format("%3d:%02d:%02d", hours, minutes, seconds);
- // This line works the first time this is called,
- // but doesn't show changes on later calls....
- text_timer.setText( message );
- // uncomment for debugging
- //System.out.println(message);
- }
- }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
Here is my layout file, pretty simple....
Using xml Syntax Highlighting
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:background="#ffffffff"
- >
- <TextView
- android:id="@+id/text_timer"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="000:00:00:00"
- android:textSize="24sp"
- android:textStyle="bold"
- android:layout_gravity="center_horizontal|top"
- android:textColor="#ff000000" />
- </LinearLayout>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4

]

