eclipse Android SDK 片段支持
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8867134/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android SDK Fragment Support
提问by Ice Phoenix
Ok i'm just starting to get into Android programming now, and I'm following the android "TabActivity" tutorial: http://developer.android.com/reference/android/app/TabActivity.html. Everythings working but it can't seem to find some of the support classes, see the code below that is generating the errors.
好的,我现在刚刚开始进入 Android 编程,我正在关注 android“TabActivity”教程:http: //developer.android.com/reference/android/app/TabActivity.html。一切正常,但似乎无法找到一些支持类,请参阅下面生成错误的代码。
mTabManager.addTab(mTabHost.newTabSpec("simple").setIndicator("Simple"),
FragmentStackSupport.CountingFragment.class, null);
mTabManager.addTab(mTabHost.newTabSpec("contacts").setIndicator("Contacts"),
LoaderCursorSupport.CursorLoaderListFragment.class, null);
mTabManager.addTab(mTabHost.newTabSpec("custom").setIndicator("Custom"),
LoaderCustomSupport.AppListFragment.class, null);
mTabManager.addTab(mTabHost.newTabSpec("throttle").setIndicator("Throttle"),
LoaderThrottleSupport.ThrottledLoaderListFragment.class,null);
For FragmentStackSupport/LoaderCursorSupport/LoaderCustomSupport/LoaderThrottleSupport, it says for all of them cannot be resolved to a type. I've added the latest support library to a folder in the root directory named "libs" and also coppied it into "C:/Eclipse/v4/" directory. My import files are:
对于 FragmentStackSupport/LoaderCursorSupport/LoaderCustomSupport/LoaderThrottleSupport,它表示所有这些都无法解析为类型。我已将最新的支持库添加到名为“libs”的根目录中的文件夹中,并将其复制到“C:/Eclipse/v4/”目录中。我的导入文件是:
import java.util.HashMap;
import android.R;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.View;
import android.widget.TabHost;
import cowdawg.hello_tab.namespace.R.layout;
import cowdawg.hello_tab.namespace.R.id;
Could someone please offer me some advice on how to solve this, thanks :).
有人可以就如何解决这个问题给我一些建议吗,谢谢:)。
回答by MH.
It's probably because the following classes are not part of the standard Android API (or the support library), but only exist in the support demos sample code for demonstration purposes:
这可能是因为以下类不是标准 Android API(或支持库)的一部分,而仅存在于支持演示示例代码中,用于演示目的:
FragmentStackSupport.CountingFragment
LoaderCursorSupport.CursorLoaderListFragment
LoaderCustomSupport.AppListFragment
LoaderThrottleSupport.ThrottledLoaderListFragment
You will need to add these classes to your own project in order to be able to use them. Hereyou can find the source files under the subsection 'Files'.
您需要将这些类添加到您自己的项目中才能使用它们。在这里,您可以在“文件”小节下找到源文件。
回答by Shekh Akther
On Eclipse IDE: Select your project and then right click on the project -> Android Tools -> Add Support Library.
在 Eclipse IDE 上:选择您的项目,然后右键单击该项目 -> Android 工具 -> 添加支持库。
Required support library will be added on your project build path. You will found this library jar under Java Build Path -> Libraries tab -> Android Dependencies.
所需的支持库将添加到您的项目构建路径中。您将在 Java Build Path -> Libraries 选项卡 -> Android Dependencies 下找到这个库 jar。
Enjoy exploring!
享受探索!
回答by Joakim Berglund
Have you added the library to your build path? Right click on the jar in eclipse -> Build Path -> Add to Build Path.
您是否将库添加到构建路径中?在 eclipse 中右键单击 jar -> Build Path -> Add to Build Path。
回答by Rajdeep Dua
Try adding by right clicking on the project and opening properties window
尝试通过右键单击项目并打开属性窗口来添加