我要如何改变一个片段里面的观点? [英] How do I change the view inside a fragment?

查看:116
本文介绍了我要如何改变一个片段里面的观点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有它创建其内部onCreateView视图如你所期望的片段。不过,我想定期更改视图。

I have a fragment which creates its view inside onCreateView as you'd expect. However I want to change the view periodically.

我的使用情况是该片段显示了Web服务的一些数据。当用户选择从列表(另一个片段)的选项,该片段应切换到一个进度条,那么一旦加载,切换到数据视图。

My use case is that the fragment shows some data from a web service. When a user chooses an option from a list (another fragment), this fragment should switch to a progress bar, then once loaded, switch back to the data view.

我可以让两个片段 - 装载片段,以及显示片段,但似乎因为这是一个封装的情况下,我宁愿做这一切的一个片段里面

I could make two fragments - the loading fragment, and the displaying fragment, but it seems that since this is an encapsulated event I'd rather do it all inside the one fragment.

基本上,我问,是什么,是的setContentView的片段里面的equivilent。

Basically what I am asking, is what is the equivilent of setContentView inside a fragment.

推荐答案

您可以使用 Fragment.getView()。这将返回容器的视图,它包含片段。在该视图中,可以调用 removeAllViews 。然后建立新的观点,并将它们添加到您得到视图 getView()

You can use Fragment.getView(). This returns the view of the container which contains the Fragment. On that view, you can call removeAllViews. Then build your new views and add them to the view you got from getView().

<一个href="http://developer.android.com/reference/android/app/Fragment.html#getView()">http://developer.android.com/reference/android/app/Fragment.html#getView()

这篇关于我要如何改变一个片段里面的观点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆