{"action":"opened","issue":{"url":"https://api.github.com/repos/codepath/android_guides/issues/194","repository_url":"https://api.github.com/repos/codepath/android_guides","labels_url":"https://api.github.com/repos/codepath/android_guides/issues/194/labels{/name}","comments_url":"https://api.github.com/repos/codepath/android_guides/issues/194/comments","events_url":"https://api.github.com/repos/codepath/android_guides/issues/194/events","html_url":"https://github.com/codepath/android_guides/issues/194","id":168270731,"number":194,"title":"use SmartFragmentStatePagerAdapter which is deployed for caching fragmets","user":{"login":"tux-world","id":6617583,"avatar_url":"https://avatars.githubusercontent.com/u/6617583?v=3","gravatar_id":"","url":"https://api.github.com/users/tux-world","html_url":"https://github.com/tux-world","followers_url":"https://api.github.com/users/tux-world/followers","following_url":"https://api.github.com/users/tux-world/following{/other_user}","gists_url":"https://api.github.com/users/tux-world/gists{/gist_id}","starred_url":"https://api.github.com/users/tux-world/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tux-world/subscriptions","organizations_url":"https://api.github.com/users/tux-world/orgs","repos_url":"https://api.github.com/users/tux-world/repos","events_url":"https://api.github.com/users/tux-world/events{/privacy}","received_events_url":"https://api.github.com/users/tux-world/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-07-29T07:57:48Z","updated_at":"2016-07-29T07:57:48Z","closed_at":null,"body":"i have some `Fragment` in my application which tey are attached on `viewPager`, after some search i found this deployed class which it is implementing cache `fragments` but i can't use that, please help\r\n\r\n```\r\n    public abstract class SmartFragmentStatePagerAdapter<T extends Fragment> extends FragmentStatePagerAdapter {\r\n    \r\n        private SparseArray<T> registeredFragments = new SparseArray<T>();\r\n    \r\n        public SmartFragmentStatePagerAdapter(FragmentManager fragmentManager) {\r\n            super(fragmentManager);\r\n        }\r\n    \r\n        // Register the fragment when the item is instantiated\r\n        @Override\r\n        public Object instantiateItem(ViewGroup container, int position) {\r\n            T fragment = (T) super.instantiateItem(container, position);\r\n            registeredFragments.put(position, fragment);\r\n            return fragment;\r\n        }\r\n    \r\n        // Unregister when the item is inactive\r\n        @Override\r\n        public void destroyItem(ViewGroup container, int position, Object object) {\r\n            registeredFragments.remove(position);\r\n            super.destroyItem(container, position, object);\r\n        }\r\n    \r\n        // Returns the fragment for the position (if instantiated)\r\n        public T getRegisteredFragment(int position) {\r\n            return registeredFragments.get(position);\r\n        }\r\n    }\r\n```\r\n\r\nnow how can i use that?\r\n\r\n```\r\n    public class MainActivity extends AppCompatActivity {\r\n    \tFragmentPagerAdapter adapterViewPager;\r\n    \r\n    \t@Override\r\n    \tprotected void onCreate(Bundle savedInstanceState) {\r\n    \t\tsuper.onCreate(savedInstanceState);\r\n    \t\tsetContentView(R.layout.activity_home);\r\n    \t\tViewPager vpPager = (ViewPager) findViewById(R.id.vpPager);\r\n    \t\tadapterViewPager = new SmartFragmentStatePagerAdapter(getSupportFragmentManager());\r\n    \t\tvpPager.setAdapter(adapterViewPager);\r\n    \t}\r\n    \t\r\n    \t// ...\r\n    }\r\n```\r\n\r\ncould you help me please ?"}}
{"actor":{"display_login":"tux-world"}}