-
Notifications
You must be signed in to change notification settings - Fork 3
Radio Group
Radio Group is a stylized RealWear view group the contains (UX Library) Radio Buttons. Much like the Android radio group, only one button can be checked at any given time, and a listener can be set on the Radio Group to listen for a change in checked state. The UX Library Radio Group extends from the Android AppCompat Radio Group.
The basic Radio Group view group can be created in an XML Layout file or programmatically.
<com.realwear.ux.viewgroup.RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
or
val radioGroup = com.realwear.ux.viewgroup.RadioGroup(context)
And that’s it! Now we need to add UX Library Radio Buttons to the Radio Group to give it content.
-
Radio Buttons: UX Library Radio Buttons extend from the Android AppCompat Radio Button and function in much the same way. They must be created and added to a Radio Group view group, and only one can be checked at any given time. A key difference is that the UX Library Radio Button is an abstract class that must be subclassed before it can be instantiated. The UX Library already includes two subclasses that are ready to be used, but a developer is also free to create their own Radio Button subclass to suit their situation. The two prepackaged subclasses are Round Radio Button and Continuous Radio Button.
-
Round Radio Button: a radio button that, when contained in a Radio Group, will group together in a series of round buttons, much like the level buttons in the Level Control component. They can be created in XML or programmatically. If created in XML, they must be contained by the Radio Group view group. If created programmatically, they will need to be added to the Radio Group.
<com.realwear.ux.viewgroup.RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.realwear.ux.view.RoundRadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</com.realwear.ux.viewgroup.RadioGroup>
or
val roundRadioButton = RoundRadioButton(context)
radio_group.addView(roundRadioButton)
- Continuous Radio Button: a radio button that, when contained in the UXLibrary Radio Group, will group together in a series that presents as a bar of options to the user. The left and right most radio buttons will have rounded edges while radio buttons in the middle will appears as a rectangle. They can be created in XML or programmatically. If created in XML, they must be contained by the Radio Group view group. If created programmatically, they will need to be added to the Radio Group.
<com.realwear.ux.viewgroup.RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.realwear.ux.view.ContinuousRadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</com.realwear.ux.viewgroup.RadioGroup>
or
val continuousRadioButton = ContinuousRadioButton(context)
radio_group.addView(continuousRadioButton)
Regardless of the subclass, all Radio Buttons share some common traits that optimize them for voice recognition. The first is that a voice command can be explicitly set for each button. The second is that a button can be designated as "title only", in which case it functions merely as a view with the radio button appearance but with no voice command registered to it. Both of these parameters can be set both in XML or programmatically.
If voiceCommand
is not set, the android:text
will be set as the voice command by default.
If titleOnly
is not set, it will default to false
.
<!-- This ContinuousRadioButton will have no voice command. -->
<com.realwear.ux.view.ContinuousRadioButton
...
app:title_only="true" />
<!-- This ContinuousRadioButton will have text "1", but the voice command is
explicitly set to "Button 1". -->
<com.realwear.ux.view.ContinuousRadioButton
...
android:text="1"
app:voice_command="Button 1" />
or
continuousRadioButton.titleOnly = true
continuousRadioButton.voiceCommand = "Button 1"
OnCheckedChangeListener and OnClickedListener: an OnCheckedChangeListener
can be set on the Radio Group and OnClickedListeners
can be set on individual Radio Buttons. This allows the developer to control the behavior of the Radio Group when a button is checked and/or clicked. These can be set the same way as for an Android AppCompat Radio Group and Radio Button.
radio_group.setOnCheckedChangeListener(object: RadioGroup.OnCheckedChangeListener {
override fun onCheckedChanged(p0: RadioGroup?, p1: Int) {
// Logic for dealing with the checked change.
}
})
radio_button.setOnClickListener(object: View.OnClickListener {
override fun onClick(p0: View?) {
// Logic for dealing with this button being clicked.
}
})