实例PagerAdapter的Andr​​oid [英] Instantiate PagerAdapter Android

查看:281
本文介绍了实例PagerAdapter的Andr​​oid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

2HI家伙,我试图建立使用水平寻呼机和支持包为Android的应用程序。我做了这个确切code编译在另一个项目,但第二code例子的最后一行是不是让我编译。 Eclipse是说无法实例类型PagerAdapter

2Hi guys I'm trying to build an app using a horizontal pager and the support package for Android. I've made this exact code compile in another project but the last line of the second code example is not letting me compile. Eclipse is saying Cannot instantiate the type PagerAdapter

我的进口

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;

我的code

List<Fragment> fragments = new Vector<Fragment>();
    fragments.add(Fragment.instantiate(this, Tab1.class.getName()));
    fragments.add(Fragment.instantiate(this, Tab2.class.getName()));
    fragments.add(Fragment.instantiate(this, Tab3.class.getName()));
    this.mPagerAdapter  = new PagerAdapter(super.getSupportFragmentManager(), fragments);

你觉得有什么问题我进口或项目设置 - 让我知道如果你需要更多的信息。这code在其他项目中工作过。

Do you think there is something wrong with my imports or project set up - let me know if you need more information. This code has worked in other projects.

感谢

推荐答案

<一个href=\"http://developer.android.com/reference/android/support/v4/view/PagerAdapter.html\">PagerAdapter是摘要类 - 你不能实例化。你必须创建一个新的类,从 PagerAdapter 继承并使用它。

PagerAdapter is an abstract class – you cannot instantiate it. You have to create a new class that inherits from PagerAdapter and use that instead.

这篇关于实例PagerAdapter的Andr​​oid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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