Widgets

  1. Definition of a widget, which is a subclass of class View.
  2. List of widget classes, including
    1. Button
    2. CheckBox
    3. EditText
    4. RadioButton and RadioGroup
    5. TextView
    6. ToggleButton
    7. SeekBar
    8. RatingBar (crashes my app: “Unfortunately, Widgets has stopped.”)
  3. Tutorial for building a form out of widgets.

Not enough time to display Toast with every change of the SeekBar’s value.

Inside the onClick method of a listener, we must say WidgetsActivity.this to refer to the Activity object. If we had said this, we would have referred to the listener object.

Source code in Widgets.zip

  1. WidgetsActivity.java
  2. R.java
  3. main.xml. Don’t have to specify the alpha level in main.xml in this example, but we will have to specify it in the next example.

Apidemos/Views/Rating Bar

When you touch the top two RatingBars in ApiDemos, it says “Unfortunately, ApiDemos has stopped.” See the java.lang.NullPointerException in the LogCat pane of the Debug perspective of Eclipse.

  1. RatingBar1.java
  2. ratingbar_1.xml

Things to try

  1. Can you make one of the radio buttons appear initially checked?

  2. Why does the RatingBar crash the app? Does it crash the app in every version of Android? Would a programmatically created RatingBar rating bar crash the app?
  3. Make a RatingBar widget (five stars). Tutorial, class RatingBar.