So I have this app it has one main activity, 3 fragments controlled by a viewpager. So it is a Tabbed Application. I have one TabPagerAdapter which extends FragmentPagerAdapter and in this class getItem returns new fragment();
My second problem is that when I close my app the fragments which were all populated lose all their views and I have to refresh my listviews again. So is there any way in which I can make the fragment retain it's views and data on opening and closing of the app like the twitter and facebook apps where the feed is maintained to the last synced feed.
I have seen the answers where they say i should make a static initialize() method and call that in tabsadapter but since my data is in an Arraylist how would store this in a bundle ?
Can you provide sample code for this aswell ?
I'm sorry I know the question is very vague and I am asking for a huge answer but i am really stuck with this and cant find a suitable solution.
My solution to the problem was to as suggested by Amrut Bidri in the comments was to set up a file and then store the data in that and load from that when fragment is created.
Related
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
I have an existing .xib that needs to be displayed as the main page in a Xamarin.Mac application. If I set the "Main Interface" as this existing .xib, it does display but it's not done by the time my DidFinishLaunching override gets called. This is where I expect to do some initialization, but the outlets I specified are all null.
I am new to Xamarin and I'm trying to figure out if I need to override a different call that lets me know that the main page is done loading or if the issue lies elsewhere.
I did see that an NSWindowController has a WindowDidLoad override, but if I set the Main Interface in the info.plist, how does it know what the ViewController is for that view so that my override WindowDidLoad gets called?
I'm thinking I probably need to create the main window manually in DidFinishLaunching, but I can't find any documentation on how to create the main window through an .xib. There is documentation on how to get a storyboard from a nib, but I am not seeing anything on loading a .xib. If someone can find a good reference on how the main window gets initialize (with all the plumbing included) in a Xamarin.Mac application, that may be enough.
Thank you in advance for your time.
The chain of events is roughly:
Main invokes NSApplication.Main
Reads Info.plist to determine what xib/storyboard to load.
Storyboard is loaded and inflated. The view controller has a custom class that points to "ViewController"
Your ViewController is spun up, and WindowDidLoad get called.
DidFinishLaunching is not exactly what you are looking for.
May I suggest take a look at the documentation in question to get a better understand of the full process:
https://developer.xamarin.com/guides/mac/getting_started/hello,_mac/#Anatomy_of_a_Xamarin.Mac_Application
I want to start an activity in a fragment and the activity is just like any other installed applications. eg. Email.
I get the intent of that application from PackageManager, now I want to start that activity in my seperate Fragment. Whenever I use startActivityFromFragment is starts the application in whole screen, but I want to start that activity limited in only that fragment.
What should I do?
Drop the idea as it doesn't really make sense and I can't see that it can be done anyway.
For example if you have a dual-pane layout and want to invoke the contacts app into the right fragment which itself uses a dual-pane layout along with making use of the application bar how would you expect it to look? It's the contacts app that is making the call to setContentView and deciding how to layout itself out, not your app. If I'm mistaken in what you mean and it's your activity then of course you can create a fragment from it and load into your required view.
this is a very basic question but I could not figure out.
My flex application gets some parameters from URL when the application opens for the first time(ex: layout=<1,2,3,4> ). Based on layout(1,2,3,4) value I have to change the layout. However the problem is the application is already drawn(Layout is initialized) by the time the control reaches the point where it reads the values from the URL.
I was wondering how can I redraw once I read the values from URL. Some thing like refresh.
Or is there a better approach to my problem.
thank you
I am not sure if this is the right approach but I fixed my problem my calling the function which is responsible for layout in applicationComplete.
It works great now.
The better approach would be to wait for the URL to be parsed and then create your view based on that value.
This means that your Main.mxml should be empty when the application loads and when you parse the URL add your MainView to the application.
Something like
- CreationComplete
- ParseURL
- AddMainViewElement
According to the adobe documentation:
"After all components are created and drawn, the Application object dispatches an applicationComplete event. This is the last event dispatched during an application startup."
( http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7ee6.html)
so "applicationComplete" event fired after all the components created.
I am navigating from tableview1.row to a tableview2 which has a LOT of rows being fetched. Given the load time is around 3 seconds, I want the navigation to slide into tableview2 as soon as the tableview1.row is selected, and then display a UIActivityIndicatorView above tableview2 whilst the data is fetched and then rendered in its underlying table view. Note, tableview2 is actually a subview of the parent UIView (as opposed to the parent being a UITableView).
I've seen this post: Activity indicator should be displayed when navigating from UITableView1 to UITableView2
... which gives instructions to add the activity indicator start and stopAnimating calls around the data fetch into viewDidLoad of tableview2.
Thing is, I'm not sure how the above solution could work as viewDidLoad runs and completes before tableview2 visibly slides into view.
Separately, I also tried adding an activity indicator over tableview2 in IB and added the IBOutlet indicator's start/stop animating code into viewDidAppear. What happens is the data fetch runs and I can see the indicator spinning but at the end of the fetch, the table view is empty. Seems like viewDidAppear is too late to add data to the table view as cellForRowAtIndexPath etc has already fired.
Can anyone please suggest any pointers? I could very well be missing something obvious here (its nearly 5am where I am and think my brain is mush). Should I re-trigger cellForRowAtIndexPath etc from viewDidAppear? Is the issue that my table view is a subview and not the parent view?
Thanks
I took another look at my own question and the answer is actually pretty straight forward. Any very intensive processing should generally not be run on the main thread. I was attempting to do my data intensive fetch AND UI display of the activity indicator on the same thread and so these were being processed in sequence, one after the other.
Solution is to enter my new view controller and a) kick off the activity indicator animation on the main thread and then b) run the data intensive fetch on another thread (using performSelectorInBackground). Any UI related updates cannot be applied from the background thread. These should be handed back to the main thread.
Plenty of SO posts on this already (example here), my bad for not picking up on these from the start :)