0

我在 android 上为滑块寻呼机输入这个示例

http://developer.android.com/training/animation/screen-slide.html

但我在这一行得到一个错误 mPagerAdapter = new ScreenSliderPagerAdapter(getFragmentManager());

错误消息:构造函数*未定义

有人可以解释为什么项目错误吗?

下面的代码

import java.util.Locale;

import android.app.*;
import android.os.Bundle;

import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class SignOnActivity extends FragmentActivity  {

private static final int NUM_PAGES = 1;

private ViewPager mPager;

private PagerAdapter mPagerAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sign_on);

    mPager = (ViewPager)findViewById(R.id.pager);
    mPagerAdapter = new ScreenSliderPagerAdapter(getFragmentManager());
    mPager.setAdapter(mPagerAdapter);

}

@Override
public void onBackPressed() {
    if (mPager.getCurrentItem() == 0) {
        super.onBackPressed();
    } else {
        mPager.setCurrentItem(mPager.getCurrentItem()-1);
    }
}



public class ScreenSliderPagerAdapter extends FragmentStatePagerAdapter {
    public ScreenSliderPagerAdapter(android.support.v4.app.FragmentManager fm) {
        super(fm);
    }

    @Override
    public android.support.v4.app.Fragment getItem(int position) {
        return new ScreenSliderPageFragment();
    }

    @Override
    public int getCount() {
        return NUM_PAGES;
    }
}

}
4

2 回答 2

0

更改: mPagerAdapter = new ScreenSliderPagerAdapter(getFragmentManager());

to : mPagerAdapter = new ScreenSliderPagerAdapter(getSupportFragmentManager());

于 2013-08-16T02:40:58.543 回答
0

您调用 FragmnetManager 可能来自不同版本的支持库。它与 ScreenSliderPagerAdapter 中的构造函数不匹配。检查导入并仅导入 v4 支持库片段管理器。或者只是添加 v4 支持库并删除其他支持库。

于 2013-08-16T02:11:36.320 回答