当我们滚动到下一个片段页面时,我正在使用 ViewPageIndicator 并尝试使用 Toast 来显示.
I am using a ViewPageIndicator and trying to use a Toast to display when we scroll to the next fragment page.
我让他跟随错误
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;
}
}
片段不扩展上下文.您必须让活动作为上下文传递.
Fragments don't extend context. You have to get the activity to pass as the context.
Toast.makeText(PlaceDetailsFragment.this.getActivity(), "Changed to page " + position, Toast.LENGTH_SHORT).show();
这篇关于Toast 类型中的方法 makeText 不适用于参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!