Friday, July 19, 2013

[android help] method getfragmentmanager() is undefined


method getfragmentmanager() is undefined



I am making a view pager to make a slide show for images. I took code from Android developers, but I was facing some issues, fragment was not recognized, I think it was because my android was 2.33. So to solve that I imported a jar file android.support.v4.jar My issues were resolved but now I am getting this error that getfragmentmanager() is undefined and another issue "The method invalidateOptionsMenu() is undefined for the type new ViewPager.SimpleOnPageChangeListener(){}"


Here is my code, can any one please help ?? My platform is 2.3.3 and api level is 10 and in manifest I have this



android:minSdkVersion="8"
android:targetSdkVersion="15" />


Code :



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;
}
}
}


Read more

stackoverflow.comm



No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...