Android Viewpager in Fragment
So I'm trying to make an Swipe Image slider in a fragment and this is what
I've Got The app crashes when I set the adapter , Not sure exactly where
the problem is.
It was working ok before I put the viewpager in a fragment
public class Slider extends Fragment {
private static final int NUM_PAGES = 5;
private TheAdapter adapter;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View view =inflater.inflate(R.layout.activity_reader, container, false);
ViewPager pager = (ViewPager) view.findViewById(R.id.pager);
adapter = new TheAdapter(getFragmentManager());
pager.setAdapter(adapter);
return view;
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onViewCreated(view, savedInstanceState);
}
And this is the adapter class
public class TheAdapter extends FragmentStatePagerAdapter{
private static final int NUM_PAGES = 5;
LayoutInflater inflater;
public TheAdapter(android.support.v4.app.FragmentManager fm) {
super(fm);
// TODO Auto-generated constructor stub
}
@Override
public boolean isViewFromObject(View view, Object object) {
// TODO Auto-generated method stub
return view == ((ViewGroup) object);
}
@Override
public void destroyItem(ViewGroup container, int position, Object
object) {
// TODO Auto-generated method stub
((ViewPager) container).removeView((View)object);
}
public Fragment getItem(int arg0) {
// TODO Auto-generated method stub
return new Slider();
}
@Override
public void destroyItem(View container, int position, Object object) {
// TODO Auto-generated method stub
super.destroyItem(container, position, object);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return NUM_PAGES;
}}
}
Nice blog, It seems to be informative..
ReplyDeleteThanks for sharing..
Selenium Training in Bangalore
It's a wonderful post and very helpful, thanks for all this information about Android.You are including better information regarding this topic in an effective way.Thank you so much.
ReplyDeleteSelenium Training in chennai | Selenium Training in annanagar | Selenium Training in omr | Selenium Training in porur | Selenium Training in tambaram | Selenium Training in velachery
This comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteGreat post! I am actually getting ready to across this information, It’s very helpful for this blog. Also great with all of the valuable information you have Keep up the good work you are doing well.
ReplyDeleteCRS Info Solutions Salesforce training for beginners