How to swap fragment in viewpager?

How to swap ViewPager with fragment

  • I have tab bar with ViewPager and some List, that i can click and get my ViewPager behind fragmant. I have some issues with changing my android.support.v4.view.ViewPager with fragment by using replace. here is my layout in wich i contain them: <RelativeLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="6"> <fragment android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/orders_fragment" android:name="fragments.OrderFragment1" tools:layout="@layout/fragment_2" /> <android.support.v4.view.ViewPager android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/primaryColor"/> </RelativeLayout> I'm trying to do it this way: list.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { FragmentManager manager = getSupportFragmentManager(); FragmentTransaction transaction=manager.beginTransaction(); Fragment f1 = manager.findFragmentById(R.id.pager); transaction.remove(f1); transaction.commit(); } }); Were i am wrong? can i do this in my way? or there is some special way to do this kind of things? Im new in this so if some1 have an example or something it wood be grate.

  • Answer:

Zoltan Kurtyak at Stack Overflow Visit the source

Was this solution helpful to you?

Other answers

ViewPager should be the fisrt element of the layout. Now it's probably the fragment is not clickable and focusable. Try this: <RelativeLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="6"> <android.support.v4.view.ViewPager android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/primaryColor"/> <fragment android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/orders_fragment" android:name="fragments.OrderFragment1" tools:layout="@layout/fragment_2" /> </RelativeLayout> Also, you have here an example of http://stackoverflow.com/a/18413437/4195050

juliocb92

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.