Settextvalue progress

This preview shows page 77 - 82 out of 99 pages.

.setText("Value: "+progress); seekBar.setSecondaryProgress( (progress+seekBar.getMax())/2); } }); Although the SeekBar value is shown visually, it might be useful to show the user the exact value selected. To do this, you can provide an implementation of the onProgressChanged() method, as shown here. There are two interesting things to notice in this example. The first is that the fromTouch parameter tells the code if the change came from the user input or if, instead, it came from a programmatic change as demonstrated with the regular ProgressBar controls. The second interesting thing is that the SeekBar still enables you to set a secondary progress value. In this example, we set the secondary indicator to be halfway between the user’s selected value and the maximum value of the ProgressBar . You might use this feature to show the progress of a video and the buffer stream.
Image of page 77

Subscribe to view the full document.

Other Valuable User Interface Controls Android has a number of other ready-to-use user interface controls to incorporate into your applications. The following section is dedicated to introducing the following: RatingBar Time controls, such as Chronometer DigitalClock TextClock AnalogClock
Image of page 78
Displaying Rating Data with RatingBar Although the SeekBar is useful for allowing a user to set a value, such as the volume, the RatingBar has a more specific purpose: Showing ratings or getting a rating from a user By default, this ProgressBar uses the star paradigm, with five stars by default. A user can drag across this horizontally to set a rating. A program can set the value as well. However, the secondary indicator cannot be used because it is used internally by this particular control.
Image of page 79

Subscribe to view the full document.

Displaying Rating Data with RatingBar (Cont’d) <RatingBar android:id="@+id/ratebar1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:numStars="4" android:stepSize="0.25" /> Here’s an example of an XML layout resource definition for a RatingBar with four stars. This layout definition for a RatingBar demonstrates setting both the number of stars and the increment between each rating value. In this layout definition, a user can choose any rating value between 0 and 4.0 , in increments of 0.25 , the stepSize value. For instance, users could set a value of 2.25 . This is visualized for users, by default, with the stars partially filled.
Image of page 80
Displaying Rating Data with RatingBar RatingBar rate = (RatingBar) findViewById(R.id.ratebar1); rate.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() { public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromTouch) { ((TextView)findViewById(R.id.rating_text)) .setText("Rating: "+ rating); } }); Although the RatingBar value is indicated to the user visually, you might still want to show a numeric representation of this value. You can do this by implementing the onRatingChanged() method of the RatingBar.OnRatingBarChangeListener class, as shown here.
Image of page 81

Subscribe to view the full document.

Image of page 82
  • 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