Android – method maketext in toast type is not applicable to parameters
•
Android
I'm using the viewpage indicator and trying to use toast when we scroll to the next fragment page
I got him to follow the mistake
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;
}
}
resolvent:
Fragments do not extend the context. You must pass the activity as a context
Toast.makeText(PlaceDetailsFragment.this.getActivity(), "Changed to page " + position, Toast.LENGTH_SHORT).show();
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码