导航组件-自定义视图状态已被上一个视图覆盖

问题描述

我正面临着奇怪的行为,我在不使用实时数据的情况下使用导航组件。我创建了自定义视图(复合视图),并在需要的地方添加了该视图。例如

public class InputCompoundView extends ConstraintLayout {
  private ViewInputTextBinding binding;

  public InputCompoundView(Context context) {
      this(context,null);
  }

  public InputCompoundView(Context context,AttributeSet attrs) {
      this(context,attrs,0);
  }

  public InputCompoundView(Context context,AttributeSet attrs,int defStyleAttr) {
      super(context,defStyleAttr);
      binding = DataBindingUtil.inflate(LayoutInflater.from(context),R.layout.view_input_text,this,true);
  }
}

在片段布局中,我根据字段多次使用上述自定义视图,例如firstName,lastName和email。视图显示良好。但是问题是,当我导航到下一个片段并再次回到该片段时,其他两个视图值已被替换为电子邮件值。

注意-此问题与不使用liveData 无关,仅供参考,我还尝试在onViewCreated上设置硬编码值,但即使这些值也已被电子邮件替换值。

仅供参考,如果我不使用自定义视图,只需在片段布局中添加view_input_text布局,就可以正常工作。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)