我在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;
}
}
}
答案 0 :(得分:0)
您的调用FragmnetManager可能来自支持库的不同版本。它与ScreenSliderPagerAdapter中的构造函数不匹配。检查导入,然后导入v4支持库片段管理器。或者只是添加v4支持库并删除其他库。
答案 1 :(得分:0)
更改: mPagerAdapter = new ScreenSliderPagerAdapter(getFragmentManager());
到: mPagerAdapter = new ScreenSliderPagerAdapter(getSupportFragmentManager());