android fragment internal notes


Android fragment is really awesome. somehow i kept on forgetting how to implement it after a few weeks down the road. :)

Full source code for this is available in github.

Simple Fragment 

To create a basic fragment on your activity that looks like this :-


Say this is a Fragment A and when you swipe, it goes to Fragment 2.

To create this simple layout, you need

a) ViewPager on your layout.



b) Create a FragmentPagerAdapter



c) Of course your fragments.



d) Tied the Viewpager to Fragment Pager Adapter - There is only 3 liner to tied our fragments layout together as shown below :-




Hopefully i won't forget about this implementation.


Tab with Fragment 

Let's have some fun with tab fragment.

For this case, we need to do all above with one step to add a control in your AppBarLayout called TabLayout.



So, please refer to step a to d above.

Tying it all together with the follow code :-











Comments

Popular posts from this blog

The specified initialization vector (IV) does not match the block size for this algorithm