I am using a ViewPageIndicator and trying to use a Toast to display when we scroll to the next fragment page.
i am getting he following error
The method makeText(Context, CharSequence, int) in the type Toast is not applicable for the arguments (PlaceDetailsFragment, String, int)
PlaceDetailsFragment.java
public class PlaceDetailsFragment extends SherlockFragment {
ImageFragmentAdapter mAdapter;
ViewPager mPager;
PageIndicator mIndicator;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_place_details, container,
false);
mAdapter = new ImageFragmentAdapter(getActivity()
.getSupportFragmentManager());
mPager = (ViewPager) view.findViewById(R.id.pager);
mPager.setAdapter(mAdapter);
mIndicator = (CirclePageIndicator) view.findViewById(R.id.indicator);
mIndicator.setViewPager(mPager);
((CirclePageIndicator) mIndicator).setSnap(true);
mIndicator.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageSelected(int position) {
Toast.makeText(PlaceDetailsFragment.this, "Changed to page " + position, Toast.LENGTH_SHORT).show();
}
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
return view;
}
}
use container parameter of fragment
Fragments don't extend context. You have to get the activity to pass as the context.
PearsonArtFoto already gave you the answer, but I like to add some information: You have to use getActivity() since you are not calling this inside an Activity(or something that extends Activity). Activity is a context(it extends context), fragment does not.