安卓在Activity中获取Fragment中的控件

来源:互联网 发布:知乎hfp护肤品怎么样 编辑:程序博客网 时间:2024/05/17 22:21
安卓在Activity中获取Fragment中的控件,这个需求很少用到,但在做项目的过程中,遇到了。其实也很简单:

```
首先在Activity中实例化Fragment
ExampleFragment exFragment = (Fragment)getFragmentManager().findFragmentById(fragmentID);
然后获取Fragment中的控件
TextView tv =(TextView) exFragment.getView().findViewById(tvID);

```
这样就OK了
```
0 0
原创粉丝点击