我正在制作一个视图寻呼机,为图像制作幻灯片。我从Android开发人员那里获取代码,但我遇到了一些问题,片段未被识别,我认为这是因为我的机器人是2.33。所以要解决我导入一个jar文件android.support.v4.jar 我的问题已经解决,但现在我收到了getfragmentmanager()未定义的错误 另一个问题“新的ViewPager.SimpleOnPageChangeListener(){}”
类型未定义方法invalidateOptionsMenu()这是我的代码,任何人都可以帮忙吗? 我的平台是2.3.3,api级别是10,在清单中我有这个
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
代码:
package com.example.profilemanagment;
import android.support.v4.app.Fragment;
import android.support.v4.app.*;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.NavUtils;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.Menu;
import android.view.MenuItem;
public class ScreenSlideActivity extends FragmentActivity {
/**
* The number of pages (wizard steps) to show in this demo.
*/
private static final int NUM_PAGES = 5;
/**
* The pager widget, which handles animation and allows swiping horizontally to access previous
* and next wizard steps.
*/
private ViewPager mPager;
/**
* The pager adapter, which provides the pages to the view pager widget.
*/
private PagerAdapter mPagerAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_screen_slide);
// Instantiate a ViewPager and a PagerAdapter.
mPager = (ViewPager) findViewById(R.id.pager);
mPagerAdapter = new ScreenSlidePagerAdapter(getFragmentManager());
mPager.setAdapter(mPagerAdapter);
mPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
// When changing pages, reset the action bar actions since they are dependent
// on which page is currently active. An alternative approach is to have each
// fragment expose actions itself (rather than the activity exposing actions),
// but for simplicity, the activity provides the actions in this sample.
invalidateOptionsMenu();
}
});
}
/**
* A simple pager adapter that represents 5 {@link ScreenSlidePageFragment} objects, in
* sequence.
*/
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
public ScreenSlidePagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
return ScreenSlidePageFragment.create(position);
}
@Override
public int getCount() {
return NUM_PAGES;
}
}
}
答案 0 :(得分:4)
从文档中引用。
使用此类(FragmentActivity
)而不是新平台的内置片段和加载程序支持时,必须分别使用getSupportFragmentManager()
和getSupportLoaderManager()
方法来访问这些功能。< / p>
由于您要延长FragmentActivity
使用getSupportFragmentManager()
http://developer.android.com/reference/android/support/v4/app/FragmentActivity.html
检查文档
FragmentActivity
没有getFragmentManager()