Multiple fragment instances with multiple RecyclerView adapters - android-fragments

I have a fragment where I create the RecyclerView and I want to make another instance of that fragment with the same RecyclerView but with different Adapter to bind different data, someone knows how to do it ?
Should I create the adapter outside the fragment and send it by the fragment constructor ?

Related

send data to one fragment to other fragment in viewpager

I am using 3 fragment in viewpager and try to communicate between all fragments(send data)
I am using 3 fragment in viewpager and try to communicate between all fragments(send data)
There are a number of different ways to share data between fragments, I like using a shared view model, the different ways are outlined in https://androidwave.com/passing-data-between-fragments/

How to use multiple viewmodels in single fragment in Android?

Let's say I have DashboadFragment which has its own ViewModel named DashboadViewModel. I have created separate layout for AutoCompleteTextView which is included in fragment_dashboard.xml file. I have created separate ViewModel for AutoCompleteTextView which is AutoCompleteTextViewViewModel. So here I have tried to observe the data which are typing in AutoCompleteTextView into DashboardFragment but it didn't worked.
I have recently started development in MVVM Pattern.
You can pass data between Fragment using the delegate viewModels
private val viewModel: ListViewModel by viewModels({requireParentFragment()})
it does mean that you will have in your dashboardFragment a AutoCompleteTextViewViewModel.
Another solution will be to use the setFragmentResult()API
See https://developer.android.com/guide/fragments/communicate#share_data_between_a_parent_and_child_fragment
and https://developer.android.com/guide/fragments/communicate#fragment-result for more informations

Pass ArrayList<String> from fragment to another fragment

I have a problem. I'm building an Android app. I created a Tabbed Activity with Android Studio. I have 3 tabs. I created 3 classes java with their relative xml. In first tab I take data from internet with Jsoup and i put these data in 2 ArrayList. I want to pass these ArrayList to tab2 and tab3 to avoid downloading again these data.
How can i do? I tried with bundle and getter/setter but I have not been successful
The solution is to be make that ArrayList as static one. Once you got the required data in fragment A then assign that data into ArrayList. Now you can easily access from anywhere.

Android Fragment instance variable vs Bundle arguments?

What is the difference between Android Fragment instance variables and the bundle arguments?
When to use what?
A Bundle is sort of presistent data. The Android runtime may restart you Activity or Fragment for example on orientation changes of your device. The variables of your first instance (let's say the one used in portrait layout) are not present when Android creates a second instance that it will use for the landscape layout.
By placing state/variables in the Bundle the new instance of your class gets back the variables, when it's recreated.
You can add the instance variables you want to keep to the Bundle in the onSaveInstanceState() method of the first instance. When the second instance is created, you get these in the Bundle that is passed to your onCreate() method.

Pass a List of Objects from a support.v4 FragmentActivity to a fragment

I am working in an android application and I want to pass a List of Objects from my fragment activity to Fragment. And I am using android support library to implement fragments since minSdkVersion is 8.
I have already passed these List of Objects from one activity to another activity by implementing my model classes with Parcelable.
So please suggest me a good solution to pass my List of objects from my fragment activity to Fragment. .

Resources