以编程方式在RadioRealButtonGroup中添加和删除按钮

时间:2019-04-30 18:14:09

标签: android kotlin

我需要以编程方式添加和删除RadioRealButtonGroup中的按钮。有谁知道如何做到这一点?更具体地说,如何删除按钮而不打扰我的RadioRealButtonGroup,因为我根据api rest中消耗的数据填充了该组。

使用的lib:(https://github.com/ceryle/RadioRealButton

我已经尝试过分别通过索引(.removeViewAt)和一次(.removeAllViews)分别删除每个视图(.removeView)。全部失败

我的xml

<co.ceryle.radiorealbutton.RadioRealButtonGroup
        android:id="@+id/rrb_tag_value"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp"
        android:textAlignment="center"
        app:layout_constraintBottom_toBottomOf="@+id/btn_readTag"
        app:layout_constraintEnd_toStartOf="@id/ib_delete_tag"
      app:layout_constraintStart_toEndOf="@+id/tv_consumption_activation"
        app:layout_constraintTop_toTopOf="@+id/btn_readTag"
        app:rrbg_animateDrawables_enter="fastOutLinearIn"
        app:rrbg_borderColor="@color/border_button"
        app:rrbg_borderSize="0.5dp"
        app:rrbg_dividerColor="@color/icon_color"
        app:rrbg_dividerSize="0.5dp"
        app:rrbg_radius="3dp"
        app:rrbg_selectorColor="@color/colorPrimary"
        app:rrbg_selectorFullSize="true" />

在radioGroup上添加按钮的功能(成功运行)

private fun fillFieldTag(tagValues: MutableList<ItemTag>) {
        tagValues.forEach { tag ->
            val radioRealButton = RadioRealButton(this.context)
            radioRealButton.run {
                text = "R$ ${tag.value.asDecimal()}"
                setRipple(true)
                setHasTextColorTo(true)
                textColor = ContextCompat.getColor(this.context, R.color.text_dark)
                textColorTo = ContextCompat.getColor(this.context, R.color.all_white)
                setTextSizeSP(16F)
                setPadding(0, 16, 0, 16)
            }
            rrb_tag_value.addView(radioRealButton)
        }
        rrb_tag_value.position = 0
        showRemoveButtonsForTag()
    }

问题在于,当删除按钮以添加回无线电组时。

0 个答案:

没有答案
相关问题