android - 导航组件 - 自定义视图状态被最后一个视图覆盖
问题描述
我面临着奇怪的行为,我使用导航组件而不使用实时数据。我已经创建了自定义视图(复合视图)并在需要的地方添加了这个视图。例如
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, attrs, defStyleAttr);
binding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.view_input_text, this, true);
}
}
在片段布局中,我根据字段多次使用上述自定义视图,例如名字、姓氏和电子邮件。视图显示正常。但问题是当我导航到下一个片段并再次回到这个片段时,其他两个视图值被替换为电子邮件值。
注意- 这个问题与不使用 liveData 无关,仅供参考我也尝试在 onViewCreated 上设置硬编码值,但即使这些值也被替换为电子邮件值。
仅供参考,而如果我不使用自定义视图,只需在片段布局中添加 view_input_text 布局,似乎工作正常。
解决方案
推荐阅读
- java - LibGDX - 我如何为演员使用动态位置?
- mysql - MySql 在 Php Admin 中工作,但 Workbench 无法检测到 MySql
- c++ - 如何从显示窗口中删除 cv::circle
- c# - 如何使 ReSharper 不将所有 .Bind 语句添加到一行?
- kubernetes - pod 之间的 k8s 内存卷,或以多容器结构将服务连接到容器
- c# - 将动态创建的用户控件图像和文本高度绑定到网格单元高度 WPF
- c++ - 从 C++ dll 调用 Go dll
- c - 警告:函数“colcheck”的隐式声明 [-Wimplicit-function-declaration]
- html - 最小窗口网页设计
- wordpress - Woocommerce 结帐客户条件