So, I have 3 fragments. Explore Fragment, Expanded Version of Explore Fragment, and Detail Fragment.
When I navigate into Detail Fragment from Explore Fragment, everything is fine, the recyclerView position is not back to 0. But when navigating to Detail Fragment from the Expanded Version of Explore Fragment, then returning to it, the position is back to 0. So, how does this happen? Why is this only affecting the Expanded Version of Explore Fragment? And how do I solve this if I want to persist in the scroll position when navigating to Detail Fragment from Expanded Fragment?
Related
I have a list fragment (containing RecyclerView) and a details fragment. When navigating from list fragment to details fragment and then back to list fragment (using navigation component), the RecyclerView in the list fragment gets recreated which in my case is a bit expensive task and also the scroll position is lost. How can I save the RecyclerView contents and it's scroll position and prevent it from recreating when navigating back to list fragment...
Is there a way to open a second Fragment Page? (ie. open multiple fragment pages at the same time)
I have a database setup and when users click a button a Fragment Page pops up so they can edit the fields. I would like to try and have a sub-menu appear for comments (so they don't have to scroll all the way to the bottom of the screen).
Something like the Menu in the Material Gallery Sample would be great.
Note:
I am currently using app.showDialog(app.pageFragments.Menu); to open the Page Fragments.
Having both Fragments open side by side would be a usable options as well.
Thanks!
Here is an example diagram.
Sorry for the late reply. I'll put this as an answer because I think it will get you what you need. You could implement this if you put the page fragments directly into your page, and toggled their visible property to show/hide them.
The biggest trick here is how does the first page fragment tell the second to open? That ends up being simple, just add a custom boolean property to the first fragment. Then in the base page (which contains the two fragments) bind the visible property of the second fragment to the custom property of the first fragment. Then in the first fragment, you can set that property to "true" when you want the second fragment to show, and "false" when you want it to hide.
How to set toolbar on every fragment of viewpager? There is a single fragment with multiple instaces in viewpager have seprate toolbar.
I am stuck in this problem last two days.
Please give me your valuable feedback's.so that i can move forward.
I've got the following problem. I want to test my application with Espresso. Therefore I want to click a button which is part of the "Buttons" fragment, this fragment is located in a frame-layout in the MainActivity.
Ofcourse I can check if the frame-layout is displayed but I can not reach the layout of the fragment which is located into the frame-layout.
So my question is, how can I reach the layout of the fragment into the frame-layout, so I can click on a button into the fragment.
The result at the moment is a NoViewMatchException:
android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with id:...
Thanks in advance!
Edit: The exception shows the view hierarchy
These are the methods I'm calling:
onView(ViewMatchers.withId(R.id.buttons)).check(matches(isDisplayed()));
This is the frame-layout in the MainActivity for the buttons fragment:
onView(withText("LOCATIONS")).perform(click());
The locations buttons is in the Buttons fragment
withId on the button id in stead of withText doesn't make sense.
The question is not very clear. It does not matter which layout you are using. Espresso can locate the element on the view hierarchy. If your case, you're getting NoViewMatchException. That means the view (R.id.buttons) is not there when you're checking.
For debugging, you can add some wait (SystemClock.sleep(2000)) and check if it works.
If that works, you need to write the idling resource to wait for the buttons fragment to appear.
Please see the wireframe image http://i.imgur.com/dPAMA.png first.
I am using a ViewPager to display fragments inside a FragmentActivity. ViewPager gets fragments from the attached FragmentPagerAdapter
mViewPager = (ViewPager) findViewById(R.id.view_pager);
mAdapter = new HomePagerAdapter(getSupportFragmentManager());
mViewPager.setAdapter(mAdapter);
Suppose viewpager has 3 fragments to display say Fragment1, Fragment2, Fragment3.
In the above image 'displaying fragment1' is the title for the first fragment, "Fragment1". This fragment is a list fragment and displays a list. Fragment2 and Fragment3 have their own content to display. when the user swipes on the screen, ViewPager will display the next fragment, "Fragment2".
What i want is that, when an item from the list(displayed by Fragment1) is clicked, Fragment1 should be completely replaced with some other Fragment, say Fragment4 (this is different fragment and is not returned by the attached adapter). when Fragment4 is displayed, the actionbar should change its content. whenever user works on Fragment4 and onBackPress or an action from the ActionBar, Fragment1 with the list should be displayed again. Meanwhile ViewPager should behave the same i.e on swipe, and the next fragment(in our case Fragment2) will be displayed.
basically, i want to get the same behavior as in example at :
http://developer.android.com/training/basics/fragments/fragment-ui.html#Replace
In this example the ListFragment is displayed directly inside a FragmentActivity. I am displaying the ListFragment with a ViewPager. I want the same functionality from the above example but inside fragments displayed with ViewPager. This was very difficult to achieve before the release of Android 4.2. this version of android supports nested fragments using getChildFragmentManager() so, i see some hope.
I am trying this on my side for many days and also scanned entire stackoverflow for Q & A related to nested fragments but didn't get what i want.
So, is this possible to achieve? if yes, then how to?
This was a big problem before Android 4.2 but it seems to easier now with nested fragments, apart from ensuring the back button works. I posted my solution to your question over here: https://stackoverflow.com/a/13925130/467509
My solution answers everything you asked apart from changing the ActionBar.