1. Download our Official Android App: Forums for Android!

DestroyItem in ViewPager?

Discussion in 'Android Development' started by Saathwik, Sep 5, 2017.

  1. Saathwik

    Saathwik Lurker
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    9
    Joined:
    Jul 14, 2017

    Jul 14, 2017
    9
    0
    15
    Male
    When is the following method called?

    void destroyItem (ViewGroup container,
    int position,
    Object object)


    In ViewPager i set my adapter as follows

    myViewPagerAdapter = new MyViewPagerAdapter();
    viewPager.setAdapter(myViewPagerAdapter);

    This is my MyViewPagerAdapter class

    public class MyViewPagerAdapter extends PagerAdapter {
    private LayoutInflater layoutInflater;

    public MyViewPagerAdapter() {
    }

    @override
    public Object instantiateItem(ViewGroup container, int position) {
    layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View view = layoutInflater.inflate(layouts[position], container, false);
    container.addView(view);

    return view;
    }

    @override
    public int getCount() {
    return layouts.length;
    }

    @override
    public boolean isViewFromObject(View view, Object obj) {
    return view == obj;
    }


    @override
    public void destroyItem(ViewGroup container, int position, Object object) {
    View view = (View) object;
    container.removeView(view);
    }
    }

    What happens when i call the empty contructor in MyViewPagerAdapter? Which methods are called?
     

    Advertisement

Share This Page

Loading...