Pass ArrayList<String> from fragment to another fragment - android-fragments

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.

Related

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

Restore Data in FragmentActivity after back button Pressed

I've read a lot of things about restoring data in FragmentActivity but nothing works in my case. I tried a lot of methods to do it but it never worked.
I have a FragmentActivity containing a ViewPager with 6 or 7 fragments. These fragments are containing each one a ListView. The datas in these ListView have been retrieved from web.
I can select an item of the ListView in a fragment to open an new activity showing the detail of the selected item.
When i go back to my FragmentActivity i don't want to retrieve a new time datas from web, but getting it from a bundle or whatever allowing me to display data instantly.
I tried getLast(Custom)NonconfigurationInstance() but it is only called when a real configuration has been changed (such as screen orientation). I also tried onSavedInstanceState in FragmentActivity, in Fragment, whith and without calling the super method... I always get a null savedInstanceState bundle in my onCreate/onCreateView.
I don't have piece of code for you because i go back to zero.
Any ideas please ?
Okay i found a solution but i hate it ! anyway...
When i select an item in the list of my fragment, i put the data i want to restore in the ActivityA with a custom Class that implements Serializable, and i close ActivityA. ActivityB is launching. when i close ActivityB, i put the data iwant to restore in ActivityA. I check if my data are not null (it can be null if i don't come from ActivityB), and if they aren't, i can populate my fragments and my lists without network connection.
It's a very bad way to solve my problem, but i have really no idea why the "savedInstanceState" methods are not working in this case.

Multiple Entity framework context in asp.net

I have a web site similar to wizard from 4 steps . The site is implemented by asp.net web forms.
The wizard try to build and object and add it to the DB.
The object graph is following :
class A { B bObject ; C cObject ; D dObject}
class B {} ; class C{}; class D{};
the objects b,c,d are fetched from the database during the wizard step and filled into A.
As you know , b,c,d fetched from the DB by different contexts.
When I come to the final step to save A to the DB , the context recognize b,c,d as new objects and not just unmodified so only link them because they come from different contexts.
Any suggestion to make a clean way solving this issue ?
The different contexts caused because of the post packs.
This is one of those cases where the best answer is "don't do that!"
One way to handle this is to just have the wizard steps gather all the data necessary to create the database tables from the user, and save the data in Session state. Only when the final wizard step is executed would you then take the data from Session state and use it to create EF entities and then save the changes, all on a single context.
Another way would be to save the object graph as EF objects (still in Session state), but then, in the final wizard step, open a context and use the Attach method to attach the objects to the current context. Again, this uses a single context.

Visual Studio 2010 Report Viewer

I have been trying to use report viewer for a couple of days now and got no where. I have an ASP.Net WEB APLICATION, not a WEB SITE. Which every tutorial relates to.
I used the report viewer last week in another project and it worked perfectly.
What im trying to achive is to create a new report using business objects. NOT a SQL connection. Previously when i used the report viewer when adding new DataSet to the Report Data window all of my namespaces in my objects library (a seperate assembly) were listed and I was able to select my busines object and drag the fields to the report.
Now every time I go into the add dataset wizard there is nothing in the datasource list. If I add the report to the objects library and create an object datasource then they appear in here fine. Obviously i dont want reports in the objects library, they go in the website.
Does anyone know why the add new datasource option is disabled for Web applications? (Accessed from Data > Add new datasource)
Can anyone tell me how I can use the object datasource in the designer in the report?
my classes i want to report on have both a parameterless constructor, they return a list for the get methods. and they are all serializable.
I have found a solution for this by creating a reporting class library.
if anyone is interested I added it to my blog for future reference.
http://wraithnath.blogspot.com/2011/02/visual-studio-2010-report-viewer-object.html

crystal report datasource to business layer object colletion

In my project I want to use data source for a crystal report as collection of business layer object.
How do I do this? I have 3 projects together in my solution one of them is business object layer.
In grid and comboboxes or other controls I am able to bind these objects to the collection directly.
I know how to bind crystal report to the object collection when class is in the same project but not to the class which is in different project of current solution.
Thank you
May be its too late for you, but I'll post an answer, in the case that it helps others.
I had the same problem - where you cannot see the classes from other projects in .NET objects section of Crystal Report, but still you can add them.
Steps to add class as data source from other project:
Go to Database Expert
Click on Create new connection
Make new Connection form ADO.NET (XML)
In popup window add a full class name in the editable drop down
Click finish
Thats it ...

Resources