如何访问片段中的父活动视图 [英] How to access parent Activity View in Fragment

查看:61
本文介绍了如何访问片段中的父活动视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ActionBarActivity和片段.我正在使用FragmentPagerAdapter为我的应用程序提供片段.我的问题如何访问片段中的父活动视图"?

I have an ActionBarActivity and fragment. I am using FragmentPagerAdapter that provides fragment to my app. My question How can I access parent Activity View in Fragment ??

推荐答案

您可以使用

View view = getActivity().findViewById(R.id.viewid);

引用文档

具体来说,该片段可以通过以下方式访问Activity实例: getActivity()并轻松执行任务,例如在 活动布局

Specifically, the fragment can access the Activity instance with getActivity() and easily perform tasks such as find a view in the activity layout

这篇关于如何访问片段中的父活动视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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