我正在渲染基于从服务器获取的 JSON 响应的表单。
我的用例包括监听单选按钮的点击,根据单选按钮选择切换某些文本字段的可见性,并使用可见的 textView 刷新布局。
预期的输出应该是用现在可见的 textView 更新同一个视图,但我现在看到同一个表单两次,第一次是默认状态,第二次是更新状态。
我是否以某种方式创建了一个全新的model_
类并将其传递给控制器?我只想更改现有模型的布尔字段并更新视图。
我的模特班
@EpoxyModelClass(layout = R.layout.layout_panel_input)
abstract class PanelInputModel(
@EpoxyAttribute var panelInput: PanelInput,
@EpoxyAttribute var isVisible: Boolean,
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var context: Context,
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var textChangedListener: InputTextChangedListener,
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var radioButtonSelectedListener: RadioButtonSelectedListener,
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var validationChangedListener: ValidationChangedListener
) : EpoxyModelWithHolder<PanelInputModel.PanelInputHolder>() {
@EpoxyAttribute var imageList = mutableListOf<ImageInput>()
override fun bind(holder: PanelInputHolder) {
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
generateViews(holder, inflater, panelInput.elements) // Generates textViews, radioButtons, etc, based on ElementType enum inside Panel input
}
fun generateRadioButtonView(element: Element) {
// Created a custom listener and calling its function
radioButtonSelectedListener.radioButtonSelected(chip.id, chip.text.toString())
}
fun generateTextView() {
// Show/hide textView based on isVisible value
}
我的控制器类
class FormInputController(
var context: Context,
var position: Int, // Fragment Position in PagerAdapter
var textChangedListener: InputTextChangedListener,
var radioButtonSelectedListener: RadioButtonSelectedListener,
var validationChangedListener: ValidationChangedListener
) : TypedEpoxyController<FormInput>() {
override fun buildModels(data: FormInput?) {
val panelInputModel = PanelInputModel_(
data as PanelInput,
data.isVisible,
context,
textChangedListener,
radioButtonSelectedListener,
validationChangedListener
)
panelInputModel.id(position)
panelInputModel.addTo(this)
}
}
我的片段实现了单选按钮选中的侦听器,修改formInput.isVisible = true
并调用formInputController.setData(componentList)
请帮我解决这个问题,谢谢!