This example shows how to register the listener When the user selects a rating

This example shows how to register the listener when

This preview shows page 81 - 89 out of 99 pages.

This example shows how to register the listener. When the user selects a rating using the control, a TextView is set to the numeric rating the user entered. One interesting thing to note is that, unlike the SeekBa r, the implementation of the onRatingChange() method is called after the change is complete, usually when the user lifts a finger. That is, while the user is dragging across the stars to make a rating, this method isn’t called. It is called when the user stops pressing the control.
Image of page 81

Subscribe to view the full document.

Showing Time Passage with the Chronometer Sometimes you want to show time passing instead of incremental progress. In this case, you can use the Chronometer control as a timer. This might be useful if it’s the user who is taking time doing some task or playing a game where some action needs to be timed.
Image of page 82
Showing Time Passage with the Chronometer (Cont’d) <Chronometer android:id="@+id/Chronometer01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:format="Timer: %s" />
Image of page 83

Subscribe to view the full document.

Showing Time Passage with the Chronometer (Cont’d) final Chronometer timer = (Chronometer)findViewById(R.id.Chronometer01); long base = timer.getBase(); Log.d(ViewsMenu.debugTag, "base = "+ base); timer.setBase(0); timer.start(); A Chronometer won’t show the passage of time until its start() method is called. To stop it, simply call its stop() method. Finally, you can change the time from which the timer is counting. That is, you can set it to count from a particular time in the past instead of from the time it’s started. You call the setBase() method to do this. In this code example, the timer is retrieved from the View by its resource identifier. We then check its base value and reset it to 0 . Finally, we start the timer counting up from there.
Image of page 84
Displaying the Time Displaying the time in an application is often not necessary because Android devices have a status bar to display the current time. However, two clock controls are available to display this information: The TextClock and AnalogClock controls
Image of page 85

Subscribe to view the full document.

Using the TextClock The TextClock control was added in API Level 17. It is meant to be a replacement for the DigitalClock , which was deprecated in API Level 17. The TextClock has many more features than the DigitalClock . It allows you to format the display of the date and/or time. The TextClock allows you to display the time in 12-hour mode or 24-hour mode and even allows you to set the time zone. By default, the TextClock control does not show the seconds.
Image of page 86
Using the TextClock (Cont’d) <TextClock android:id="@+id/TextClock01" android:layout_width="wrap_content" android:layout_height="wrap_content" />
Image of page 87

Subscribe to view the full document.

Using the TextClock (Cont’d) The TextClock control was recently added in API Level 17 and is meant to be a replacement for the DigitalClock , which was deprecated in API Level 17.
Image of page 88
Image of page 89
  • Summer '16

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask You can ask ( soon) You can ask (will expire )
Answers in as fast as 15 minutes