tabbed activity fragments swipe unlock if button is clicked - java

I made a tabbed activity with two fragments and i want the activity to be locked at fragment1 unless the user click a button in fragment1 then the activity switch to fragment2 automatically and the swipe is unlocked so you can switch between fragment1 and fragment2. I have been learning java for a week now and creating this tow fragment takes me a lot of effort and headache and since i have not studied java or other programming languages i think i can't figure this one on my own please help me.

That's very simple. If you want to work it with a button, add button inside the tab, and at Onclick View call the 2nd fragment method.

Related

need onbackpressed function in MeowBottomNavigation library

https://github.com/oneHamidreza/MeowBottomNavigation
i have implemented bottom navigation bar using above library but when i press back button it is directly closing the app even when i am in another fragment alsp.
please guide me that when i press back button it should come to home fragment and when i am in another fragment the back button should work accordingly to that respective fragment.
when i press back button in bottom navigation bar it should come to home fragment if it is in another fragment other than home if it is in home fragment then it can close app.

How to go to a specific fragment of a Tabbed Activity B, from a fragment of a simple Activity A?

If two activities (for example: Activity A and a Tabbed Activity B) have different fragments each (ex: two fragments for Activity A... and two other fragments for Tabbed Activity B), then how to move from a fragment of activity A and go to a specific fragment, held by the other Tabbed Activity B? (Please see a picture here )
For example, navigating:
From : second_fragment_a of ActivityA
To : second_fragment_b , of TabbedActivityB (meaning being able to directly choose any fragment of the (other) Tabbed activity to load)
Please:
It is not about how to navigate between fragments of a same
activity, or from a fragment to another activity.
Can we call it from a drawer navigation and a toolbar...? But no
matter how you can help me with that question, as clear as possible
because I'm new to Android Studio, I'll really appreciate!
Thanks!!!

Android - add Swipe View/tabs to only SOME fragments

Currently, my app is using a navigation drawer for my fragments. However, I have 2 fragments that are related, I would like to put these under one heading on the navigation drawer and then have 2 tabs to switch between the related fragments once I select that choice on the drawer.
Is this possible with only one activity or would I have to implement another activity specifically for the tab? I've considered only adding the tabs once the right fragment is committed but that leaves the question of how to remove it once I switch to a fragment that doesn't require the tabs.
I'd also like to avoid having to implement another activity as I am trying to keep the navigation available through my whole app. I'd rather not have to create an identical drawer and then have to keep things consistent between the 2 drawers.
Edit:
So far, I've managed to make a parent fragment that has a viewpager, fragmentpageradapter, and tablayout. Swiping between the 2 tabs does indeed shift between my 2 desired child fragments. However, I am unable to change a textview in one of my child fragments from my MainActivity. I'm guessing the reason why this is the case is because technically, my parent fragment is in view, not my child fragment. Any suggestions to get around this?
Hierarchy:
MainActivity
-Navigation Drawer
--Fragment1
--Fragment2
--Fragment3
--Fragment4
---FragmentPagerAdapter (under Fragment4, tabs)
----SubFrag1
----SubFrag2
Here's how you might use FragmentStatePagerAdapter to swipe across a Fragment:
http://developer.android.com/intl/es/training/implementing-navigation/lateral.html
I hope it help you.

Putting ViewPager and tabs in a fragment and replacing it

In my main activity I have a ViewPager with two tabs and each of them has its contents in a fragment. One of the tabs holds a list of items and when I press on an item from that list I want the details of that item to appear on the screen. I thought of putting the whole ViewPager in a fragment and when the user taps the item the fragment representing the whole ViewPager is replaced with another fragment representing the details of the item. Is it possible and is it a good practice? Maybe I should just start another activity with the details of the item?
How you do it is your own choice. It's perfectly fine to switch your Fragments.
getSupportFragmentManager().beginTransaction().replace(android.R.id.content, new FragDetails())
.addToBackStack(FragPager.class.getName()).commit();
Switching to another Activity is fine too, you just have more of a "flicking" screen when opening a new Activity (and some other life cycle stuff too of course). If you don't want that, switch Fragments.

Managing multiple fragments next to each other

I am currently working on a tablet app which has 1 main activity. In this activity there are 6 buttons which represent the main menu. When clicked a fragment opens, which contains a submenu. When a submenu item is clicked another fragment is opened.
At this point I have 2 active fragments in 1 activity.
My problem is that when I click a new 'main menu' button just 1 of the 2 activities closes, the first one that was opened. I think it works like a list, first in / first out when the third activity is opened.
When I use replace and only one fragment is active there is no problem, it is closed and the other one opens.
How do I manage more than 2 fragments?
Kind regards.
I have found the awnser myself, I have to give every Fragment a name and add them to the backstack.
ft.addToBackStack("fragmentname");
When a 'main menu item' is clicked I remove all fragments from the backstack:
getFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
When I wish to selectively remove fragments from the backstack when I open een sub menu I use:
getFragmentManager().popBackStack ("film", FragmentManager.POP_BACK_STACK_INCLUSIVE);
I hope this helps some people facing the same problem.
Kind regards

Categories

Resources