Tag: fragment
-
Getting the Context inside a Fragment
It is very easy to get the Context inside an Activity: with the getApplicationContext() method using only “this” because the Activity class extends the Context class But you can’t use any of these two methods inside a Fragment and you have to replace them respectively with: getActivity().getApplicationContext() getActivity() I often do this replacement when I…
-
How to restore the state of a WebView in a layout “Tabs + Swipe” with ViewPager and FragmentPagerAdapter
In the post Tabs and swipe views Szymon asks how to implement a WebView in order to preserve its state moving from one tab to another in a similar way as explained in How to save the state of a WebView inside a Fragment of an Action Bar.
-
Saving the position of a ScrollView inside a Fragment
I thought of writing a post about how to save the position of a ScrollView when I read the Bhavin’s comment in the post Tab Layout in Android with ActionBar and Fragment. Bhavin asked how one could restore the position of a scrollview switching between a tab and the other.