How can I set values of switcher in all fragments of a viewpager, by changes one switch in MainActivity - android-fragments

I am developing one android application and it has a tab layout with ViewPager setup. I have totally 8 fragments in the viewpager. Each Fragment holding an RecyclerView. The recyclerview row has one text one switcher and one icon for rename text.
Whenever the activity started it loads 8 fragments with recyclerview data. I have a switcher in the MainActivity, whenever the MainActivity switcher it changes I need to switch all the switches from all 8 fragments and I want to save all in Lists and to send them in server.

Related

How to pass value from MainActivity to Fragment in Bottom Navigation View in Android Studio Kotlin

I am using Firebase in my project, and want to retrieve the data from the database and show it in my Text View in my profile fragment which is a part of Bottom Navigation View. I tried the bundle but it throws error for some reason. So i wanted to know is there any easy way to transfer data from main activity to fragment, specifically one row of Firebase data in different element of the fragment.
Make an interface between the the main activity and the fragment when use click to show the fragment ,fire the interface and pass the sting or what you need
another solution you can use a viewModel between the activity and fragment and fire Live data between them
you can also use EventBus

ViewPager2 with TabLayout swipes to next position on Tab tapped

I prepared on github (https://github.com/SertanAcubens/ViewPagertest) sample app to illustrate problem I encountered while migrating to ViewPager2. Shortly, one of fragments in ViewPager is built from CardViews (with RecyclerView inside) which are added in fragment's onViewCreated method. When Tab Three is tapped ViewPager2 swipes immediately to next position. I would appreciate any help on that issue.
Seems like this bug affects at least devices with Android 9. On some devices with Android 11 works OK.

set toolbar on each fragments in viewpager

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.

Launch watchkit app from long custom notification content area

I'm trying to implement a feature such that users can click on the notification content area (not app icon nor action buttons) to bring the main watchkit app open. The current official way to launch the main watchkit app is to tap the app icon or action buttons in a notification scene. But I feel like the app icon is actually quite small (and hard) to tap and sometimes users are not even aware of this feature.
What I'm trying to do now is to put my notification content into a table row in the notification controller and make this row clickable. This will give user a pretty big area to tap with. Then in the click event handler I'm trying to open the main watchkit app. But I haven't figure out a way to do that (none of the general navigation methods such as presentControllerWithName works from notification controller).
Any suggestions?

replace fragments inside fragment displayed by the viewpager

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.

Resources