我什么时候必须膨胀自定义视图的布局?
我制作了一个自定义视图,用于视图分页器的多个片段中。
视图始终存储为 Fragment 的字段。我在构造函数中膨胀了布局,并且翻阅页面一切正常。因为总是创建下一个片段,所以视图显示没有任何问题。但是,如果我返回,则会重新创建片段的已销毁视图,并且它会给我一个错误,因为我仍然使用相同的自定义视图,该视图没有膨胀,因为没有调用构造函数。
那么,什么时候我必须膨胀自定义视图的布局?我不认为代码可以解决任何问题,但如果需要的话我可以提供。
I made a custom view which is used in several Fragments of an viewpager.
The view is always stored as a field of the Fragment. I inflate the layout in the constructor and everything works fine flipping through the pages. Because always the next Fragment is created the view shows up without any problem. But if I go back a destroyed View of a Fragment is recreated and it gives me an error, because I still use the same custom view, which isn't inflated, because the constructor isn't called.
So, when do I have to inflate my layout of the custom view? I don't think code would clear anything up, but I can deliver if needed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在此函数中:
参考是此处
In this function:
The reference is HERE
我有一个包含视图的类
DynamicRowView
。您可以创建一个类并在主文件中调用该类:并将其写入您想要
View
的主类中:I have a class
DynamicRowView
which contains view. You can create a class and call the this class in your main file:and write this in your main class where you want the
View
: