Time for action - turning on the TextSwitcher
We want the
TextSwitcher to display the next listed comment every five seconds. For this we'll need to employ new resources, and a
Handler object. A
Handler is a way for Android applications and services to post messages between threads, and can also be used to schedule messages at a point in the future. It's a preferred structure to use over a
java.util.Timer since a
Handler object will not allocate a new
Thread. In our case, a
Timer is overkill, as there is only one task we want to schedule.
- Create a new XML file in your
- Copy the following code into the new
<TextView xmlns:android="http://schemas.android.com/apk/res/android" android:gravity="left|top" ...