Outofmemeoryerror (viewpager + imageviews)

后端 未结 6 880
悲哀的现实
悲哀的现实 2021-01-30 12:18

i am showing 150+ images in viewpager, when page size crossed 70 app is crashing , all images are loading from network , and i have fallowed [link]: Strange out of memory issue

6条回答
  •  旧巷少年郎
    2021-01-30 12:37

    Sheetal,

    As requested, I use the above code as follows:

    In my FragmentActivity I do the following in the onCreate() method:

    pager = (ViewPager)findViewById(R.id.pager);
    imageAdapter = new MyPagerAdapter(this, pager, theResources, listOfIds.pageBitMapIds);
    imageAdapter.setRecentListener(this);
    pager.setAdapter(imageAdapter);
    

    Then in my PagerAdapter I do the following:

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        MyFragment myFragment = new MyFragment(resources, resourceIds[position], recentListener, position);
        myFragments[position] = myFragment;
        return super.instantiateItem(container, position);
    }
    
    @Override
    public Fragment getItem(int position) {
        return myFragments[position];
    }
    

    And then I use the code in my previous answer above.

    This is obviously not complete code and it has been adapted from my actual code, but it should give you a good idea of what to do and where to do it.

    Mark

提交回复
热议问题