以下是我实例化ViewPagerAdapter
的代码。我正在关注使用活动的教程,因为我正在使用片段,我已经试图找出应该改变的内容。我的错误就在这一行
**ViewPagerAdapter viewPagerAdapter = ViewPagerAdapter.setAndroidContext(this.getActivity());**
错误显示为无法解决方法setAndroidContext()
。
public class HomeFragment extends Fragment {
ViewPager viewpager;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_home, container, false);
viewpager = (ViewPager) getView().findViewById(R.id.viewpager);
**ViewPagerAdapter viewPagerAdapter = ViewPagerAdapter.setAndroidContext(this.getActivity());**
}
}
答案 0 :(得分:-1)
尝试以下
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
View view=inflater.inflate(R.layout.fragment_home, container, false);
ViewPager pager=(ViewPager)view.findViewById(R.id.viewpager);
pager.setAdapter("your adapter");
return view;
}