无法解析法getActivity() [英] Cannot resolve method getActivity()

查看:2116
本文介绍了无法解析法getActivity()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  • 我是新来的Andr​​oid和学习按照这个结果来创建Android的碎片
    例如:片段导航抽屉

之间的code 菜单项和之间导航的添加导航标题由一个方法 getActivity()

The code between Navigating between Menu Items and Add Navigation Header consists a method getActivity().

由于作者没有提及到哪里粘贴此code,我在 MainActivity.java 文件

As the author didn't mentioned where to paste this code, I pasted in my MainActivity.java file

介于code 菜单项之间导航添加导航标题按我在正确的位置粘贴?

Is code between Navigating between Menu Items and Add Navigation Header pasted at correct location by me?

在方法 selectDrawerItem(菜单项菜单项)有评论 //创建一个新片段,并指定这个星球显示基于位置结果
笔者不希望我在这里补充一下。

In method selectDrawerItem(MenuItem menuItem) there is a comment // Create a new fragment and specify the planet to show based on position
Does author expects me to add something over here.

推荐答案

这是活动不具有 getActivity()方法。结果
片段有。

An Activity has no getActivity() method.
Fragments have.

由于 getActivity()说:回归,其中包含我的活动。

Because getActivity() says: "return the Activity which contains me".

虽然Framents包含在活动,活动本身都没有。

And while Framents are contained in Activities, Activities themselves aren't.

这篇关于无法解析法getActivity()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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