简体   繁体   English

如何在同一个项目中使用android支持库v4和v13?

[英]How can I use android support libraries v4 and v13 in the same project?

I'm trying to use both v4 and v13 support libraries and the ADT is giving me the error: 我正在尝试使用v4和v13支持库,ADT给出了错误:

Found both android-support-v4 and android-support-v13 in the dependency list.
Because v13 includes v4, using only v13.

I need to use both because I have to use: 我需要使用两者,因为我必须使用:

import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;

import android.support.v13.app.FragmentPagerAdapter;

I've tried to add the libraries as an external jar but then I'm getting NoClassDefFoundError 我试图将库添加为外部jar,但后来我得到了NoClassDefFoundError

Can I use both libraries or can I replace some of those imports? 我可以使用这两个库还是可以替换其中一些导入?

Thanks in advance 提前致谢

EDIT: 编辑:

Hello, thanks for the fast answers 您好,感谢您的快速解答

I've tried before to use the android.support.v4.app.FragmentPagerAdapter but then I got another problem. 我之前尝试过使用android.support.v4.app.FragmentPagerAdapter,但后来又遇到了另一个问题。

I have a main activity which implements a Navigation Drawer and uses a FrameLayout to load the Fragments. 我有一个主要的活动,它实现了一个导航抽屉,并使用FrameLayout来加载碎片。 This activity has a method that displays the fragments. 此活动有一个显示片段的方法。 The method has the next code: 该方法有下一个代码:

if (fragment != null) {
    FragmentManager fragmentManager = getFragmentManager();
    fragmentManager.beginTransaction().replace(R.id.frame_container, fragment).commit();

If I use android.support.v4.app.FragmentPagerAdapter I need to use also 如果我使用android.support.v4.app.FragmentPagerAdapter我也需要使用

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;

And I got the next error when using getFragmentManager(); 我在使用getFragmentManager()时遇到了下一个错误;

Type mismatch: cannot convert from android.app.FragmentManager to  android.support.v4.app.FragmentManager

I've read I can use getSupportFragmentManager() but I get another error: 我已经读过我可以使用getSupportFragmentManager()但我收到另一个错误:

The method getSupportFragmentManager() is undefined for the type ActivityMain

That's the reason I want to use both, v4 and v13 libraries 这就是我想同时使用v4和v13库的原因

SOLVED: 解决了:

The solution was make ActivityMain extends from FragmentActivity and use only v4 support library 解决方案是使ActivityMain从FragmentActivity扩展并仅使用v4支持库

如果ActivityMain类正在扩展FragmentActivity ,那么将定义getSupportFragmentManager()

According to docs, FragmentPagerAdapter is also present in support lib v4 (see docs ). 根据文档, FragmentPagerAdapter也出现在支持lib v4中(参见docs )。 So if this is the only reason you use v13 - you can easily get rid of it. 因此,如果这是您使用v13的唯一原因 - 您可以轻松摆脱它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM