兼容性库onViewCreated [英] onViewCreated with compatibility library

查看:172
本文介绍了兼容性库onViewCreated的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android应用程序中我有一个片段,实现了覆盖<一个href=\"http://developer.android.com/reference/android/app/Fragment.html#onViewCreated%28android.view.View,%20android.os.Bundle%29\"相对=nofollow> onViewCreated 设置一些OnClickListeners一旦认为是存在的。

In an Android application I have a fragment implemented that overrides onViewCreated to set up some OnClickListeners once the view is there.

当我实现这一切工作正常。但是当我加入兼容性库V4 R3似乎方法不叫的。

This all works fine when I implement. However as soon as I add the compatibility library v4 r3 it seems that the method is not called at all.

有关我现在迁移我的设置到onResume但是这确实是不理想。因此,这里是我的问题:

For now I am migrating my setup into onResume but that is really not ideal. So here are my questions:


  • 这是在兼容性库中的错误?

  • Is this a bug in the compatibility library?

有没有更好的解决方法吗?

Is there a better workaround?

在一些更多的挖掘和尝试不同的东西,我得到这个堆栈跟踪,这让我相信这确实是兼容性库中的错误。

After some more digging and trying different things I got this stacktrace, which lets me believe it is indeed a bug in the compatibility library.

10-07 14:25:11.130: ERROR/AndroidRuntime(2964): FATAL EXCEPTION: main
        java.lang.NoSuchMethodError: android.support.v4.app.Fragment.onViewCreated
        at roboguice.fragment.RoboFragment.onViewCreated(RoboFragment.java:18)

但更古怪。纵观兼容性库的来源,方法实际上是有,但它是空的。

But even more weirdly. Looking at the compatibility library source that method is actually there but it is empty.

推荐答案

很多来回调试后,我发现这个问题。原来我是在我的项目使用的是旧版本的兼容性库。现在我已经更新我的项目和事情做工精细。仅供参考所需的变化是在Maven的POM文件兼容性库的依赖是这样

After much back and forth and debugging I found the problem. It turns out I was using an old version of the compatibility library in my project. I have now updated my project and things work fine. For reference the needed change is to the compatibility library dependency in the maven pom file to be like this

        <dependency>
            <groupId>android.support</groupId>
            <artifactId>compatibility-v4</artifactId>
            <version>r3</version>
        </dependency>

与部署与Maven的Andr​​oid SDK中部署你的Maven回购库。我也有更新roboguice维基和的挂在我的github帐户依据。

这篇关于兼容性库onViewCreated的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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