英文:
how to change visibility a view in a fragment from the activity
问题
Sure, here's the translation:
正如标题中所述,如何从活动中更改片段中视图的可见性?
我的代码有一个启动活动和一个片段。我想从活动中更改片段内某个视图的可见性。
如何实现这个?
英文:
As stated in the title how can change visibility a view in a fragment from the activity?
My code has a launch activity and a fragment. I want to change the visibility of a view inside fragment from activity.
How can do this?
答案1
得分: 1
有几种方法。如果您能添加一些代码作为参考就更好了。
第一种方法是在片段中添加一个方法,将可见性设置为“gone”。在您的活动中,您可以通过getSupportFragmentManager().findFragmentById(<container - id>)
获取片段的实例,然后调用片段的方法。
第二种方法可以使用接口来实现。
英文:
There can be a couple of ways. It would nice if you add some code for the reference.
1st way would be to have a method in the fragment which would have the set the visibility to gone in fragment. In you activity you can get the instance of the fragment by this getSupportFragmentManager().findFragmentById(<container - id>)
and then just call the fragment method.
2nd way could be using interface to this.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论