Android fragment onResume() refresh data - android-fragments

I have a Fragment A with a RecyclerView.
Fragment A populates the RecyclerView items (a list of users) from SQLite and displays it in the onCreateView() method, and it works fine.
When i go to Fragment B and add a new user and hit done, i go back to Fragment A, now i should "Refresh" the users list.
I tried achieving that through moving the code from onCreateView() to onResume(). But, i have no access to a view like i do on the onCreateView().
What do you think is the best approach on handling this?
Thanks!

So, at first I suppose you should update data on your list, which one you give to your adapter. If that won't help, try to create new adapter and bind it with recyclerview in your onResume() method.

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

How to make changes one fragment recyclerview from another fragment button using interface

My activity have two tabpanes(two fragments).
Fragment1;Fragment2 ,Fragment1 have insert and delete stuff,Fragment2 have display lists use recyclerview.
If i click in Fragment1 button then want to change Fragment2 recyclerview.any exact tutorials examples available please guide me.i tried lot but not get exact .

Fragment gets destroyed everytime app is closed

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.

Populate ListView only once on fragment with FragmentTabHost Nested Fragment

I'm developing an app which has a ListView on a Fragment, I'm getting some data from SQLite using AsyncTask and filling a ListView, but every time i switch between the tabs, the ListView is populated all over again, it's not getting all the data again, but it is putting on the List again...
Is there a way to stop that? I want that my ListView is populated only once when i create the fragment. i am using Android ActionbarSherlock Nested Fragment Tabs.
You have to detach fragment an then attach again once you return to that tab, instead of remove fragment and create again.

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