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:
here is one good example for viewpager http://www.androidhive.info/2013/10/android-tab-layout-with-swipeable-views-1/
Zoltan Kurtyak at Stack Overflow Visit the source
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:
- How to use ViewPager?Best solution by Stack Overflow
- How to call Fragment from another Fragment?Best solution by Stack Overflow
- How to replace a fragment with another fragment in Android?Best solution by Stack Overflow
- How to update widget from Fragment?Best solution by Stack Overflow
- How to send data from Fragment to an Activity in Android?Best solution by forum.xda-developers.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.