Skip to content

List Item Radio Button Widget

siddutgikar edited this page May 12, 2020 · 1 revision

The widget is an extension of the List Item Title Widget. The primary purpose of this widget is to accept option inputs from user.

abstract class ListItemRadioButtonWidget<T> @JvmOverloads constructor(
        context: Context,
        attrs: AttributeSet? = null,
        defStyleAttr: Int = 0
) : ListItemTitleWidget<T>(context, attrs, defStyleAttr)

The widget provides APIs to configure the options.

  1. protected fun addOptionToGroup(label: String): Int This function enables adding an option to the widget. The function returns the index of the option added. This can be used later to modify or remove the option from the group.

  2. protected fun removeOptionFromGroup(index: Int) This function can be used to remove an existing option from the group using its index.

  3. protected fun setSelected(index: Int) This function can be used to mark an option from the group as selected using its index.

  4. protected fun setOptionTextByIndex(index: Int, text: String) This function can be used to to modify an option's text from the group using its index.

Example of the widget is RC Stick Mode List Item Widget

The UI elements can be customized to match the style of the user's application. The customizations can be done using attributes in XML or programmatically using the APIs.

Attributes

List of the customizable XML attributes
  • uxsdk_option_text_size - The size of the text diplayed on the options.
  • uxsdk_option_color_state_list - The color state list of the text diplayed on the options.
  • uxsdk_option_text_appearance - The appearance of the text diplayed on the options.
  • uxsdk_center_option_background_selector - The background selector for the options other than first and last.
  • uxsdk_first_option_background_selector - The background selector for the first option.
  • uxsdk_last_option_background_selector - The background selector for the last option.

APIs

List of the customization APIs
  • var optionTextSize: Float - The size of the text diplayed on the options.
  • var optionColorStateList: ColorStateList? - The color state list for the text diplayed on the options.
  • var centerOptionBackgroundSelector: Drawable? - The background selector for the options other than first and last.
  • var firstOptionBackgroundSelector: Drawable? - The background selector for the first option.
  • var lastOptionBackgroundSelector: Drawable? - The background selector for the last option.
  • fun setOptionTextAppearance(@StyleRes textAppearanceResId: Int) - Set the text appearance of the text displayed on the button.

Recommended selector for Option background

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_enabled="false">
        <shape android:shape="rectangle">
            // Style your item for disabled state
        </shape>
    </item>
    <item android:state_checked="true">
        <shape android:shape="rectangle">
            // Style your item for checked state
        </shape>
    </item>
    <item android:state_checked="false">
        <shape android:shape="rectangle">
            // Style your item for enabled state
        </shape>
    </item>
</selector>

Recommended selector for Option text color

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="@color/disabled_state_color" android:state_enabled="false" />
    <item android:color="@color/checked_state_color" android:state_checked="true" />
    <item android:color="@color/enabled_state_color" android:state_checked="false" />
</selector>
Clone this wiki locally