{"id":7987,"date":"2015-11-16T00:40:29","date_gmt":"2015-11-16T00:40:29","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2015\/11\/16\/change-between-fragment-navigation-drawer-viewpagerindicator-open-source-projects-jakewharton-viewpagerindicator\/"},"modified":"2022-08-30T15:03:05","modified_gmt":"2022-08-30T15:03:05","slug":"change-between-fragment-navigation-drawer-viewpagerindicator-open-source-projects-jakewharton-viewpagerindicator","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2015\/11\/16\/change-between-fragment-navigation-drawer-viewpagerindicator-open-source-projects-jakewharton-viewpagerindicator\/","title":{"rendered":"Change between fragment navigation drawer viewpagerindicator-open source projects JakeWharton\/ViewPagerIndicator"},"content":{"rendered":"<p>I have a Navigation Drawer and a ViewPagerIndicator inside the content_frame. I want to change between fragment`s from the navigation drawer but the problem is that switch between tabs <strong>ViewPager<\/strong> works but when I switch to another option that you have to remove the <strong>ViewPager<\/strong> and put a new fragment puts this fragment under the <strong>ViewPager<\/strong>.<\/p>\n<p>Attached photo so you can see.<\/p>\n<p>1) Here you can already see the new fragment below ViewPager.It can be distinguished by the text shown is <strong>Prueba<\/strong><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/VuapX.png\" \/><\/p>\n<p>Attached code<\/p>\n<p><strong>Activity_main.xml<\/strong><\/p>\n<pre><code>\n\n\n\n    \n\n        \n\n        \n    \n\n\n\n\n<\/code><\/pre>\n<p>Method for switching between fragment.<\/p>\n<pre><code>   \/** Main content by replacing fragments\n * @param position\n *\/\nprivate void selectItem(int position) {\n    \/\/Code\n    Fragment fragment = new TryFragment();\n    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();\n\n    switch (position) {\n    case 0:\n        mPager.setCurrentItem(0);\n        break;\n\n    case 1:\n        mPager.setCurrentItem(1);\n        break;\n\n    case 2:\n\n        ft.replace(R.id.content_frame, fragment);\n\n        break;\n\n    }        \n    ft.commit();\n    mAdapter.notifyDataSetChanged();\n    \/\/Close drawer\n    mDrawerLayout.closeDrawer(mDrawerList);\n}\n<\/code><\/pre>\n<p>Class TryFragment<\/p>\n<pre><code>    class TryFragment extends Fragment\n{\n    public static final String  ARG_PLANET_NUMBER   = \"planet_number\";\n\n    public TryFragment()\n    {\n        \/\/ Empty constructor required for fragment subclasses\n    }\n\n    @Override\n    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)\n    {\n           TextView text = new TextView(getActivity());\n            text.setGravity(Gravity.CENTER);\n            text.setText(\"Prueba\");\n            text.setTextSize(20 * getResources().getDisplayMetrics().density);\n            text.setPadding(20, 20, 20, 20);\n\n            LinearLayout layout = new LinearLayout(getActivity());\n            layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));\n            layout.setGravity(Gravity.CENTER);\n            layout.addView(text);\n\n            Log.d(\"TestFragment\", \"Estoy en el fragment\");\n\n            return layout;\n    }\n}\n<\/code><\/pre>\n<p>I do not know if I have to destroy the viewpager to show the new fragment or a problem of hierarchy in the xml.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have a Navigation Drawer and a ViewPagerIndicator inside the content_frame. I want to change between fragment`s from the navigation drawer but the problem is that switch between tabs ViewPager works but when I switch to another option that you have to remove the ViewPager and put a new fragment puts this fragment under the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7987","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7987","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=7987"}],"version-history":[{"count":1,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7987\/revisions"}],"predecessor-version":[{"id":8721,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7987\/revisions\/8721"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7987"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7987"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7987"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}