The code demonstrates that the notification contains the resource identifier

The code demonstrates that the notification contains

This preview shows page 55 - 62 out of 99 pages.

The code demonstrates that the notification contains the resource identifier for the specific RadioButton chosen by the user, as defined in the layout resource file. To do something interesting with this, you need to provide a mapping between this resource identifier (or the text label) and the corresponding functionality in your code. In the example, we query for the Button that was selected, get its text, and assign its text to another TextView control that we have on the screen.
Image of page 55

Subscribe to view the full document.

Using RadioGroup and RadioButton (Cont’d) final Button clear_choice = (Button) findViewById(R.id.Button01); clear_choice.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { RadioGroup group = (RadioGroup) findViewById(R.id.RadioGroup01); if (group != null) { group.clearCheck(); } } }
Image of page 56
Using RadioGroup and RadioButton (Cont’d) As mentioned, the entire RadioGroup can be cleared so that none of the RadioButton objects are selected. The following example demonstrates how to do this in response to a button click outside of the RadioGroup . The action of calling the clearCheck() method triggers a call to the onCheckedChangedListener() callback method. This is why we have to make sure that the resource identifier we received is valid. Right after a call to the clearCheck() method, it is not a valid identifier but instead is set to the value -1 to indicate that no RadioButton is currently checked. }
Image of page 57

Subscribe to view the full document.

Retrieving Dates and Times from Users The Android SDK provides a couple of controls for getting date and time input from the user. One particular control is the DatePicker control. It can be used to get a month, day, and year from the user.
Image of page 58
Retrieving Dates and Times from Users (Cont’d)
Image of page 59

Subscribe to view the full document.

Retrieving Dates and Times from Users (Cont’d) <DatePicker android:id="@+id/DatePicker01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:calendarViewShown ="false“ android:datePickerMode =”spinner” android:spinnersShown="true" /> This is a basic XML layout resource definition for a DatePicker . As you can see from this example, a couple of attributes help control the look of the picker. Setting the calenderViewShown attribute to true , when using API Level 11 and up, will show a full calendar, including week numbers, but may take up more space than you can allow. The attribute datePickerMode was added in API Level 21. This attribute was added because when using the Material theme, the calendar layout is configured by default, so setting the value of spinner forces a spinner to be used.
Image of page 60
Retrieving Dates and Times from Users (Cont’d) final DatePicker date =(DatePicker)findViewById(R.id.DatePicker01); date.init(2015, 7, 17, new DatePicker.OnDateChangedListener() { public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) { Calendar calendar = Calendar.getInstance(); calendar.set(year, monthOfYear, dayOfMonth, time.getCurrentHour(), time.getCurrentMinute()); text.setText(calendar.getTime().toString()); } }); As with many of the other controls, your code can register to receive a method call when the date changes. You do this by implementing the
Image of page 61

Subscribe to view the full document.

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