1

I am new to Android development. Also new to Java (although have ample work experience in C++/Windows)

After reading some documents and going through some links and SO answers, my understanding is:

  1. Fragments has contents (like lists, buttons, text, images etc).
  2. View pager adapter has fragments added.
  3. View pager adapter is set to view pager.
  4. TabLayout set up with ViewPager.

Thus each tab would show fragments added one by one.

Is my understanding correct?

But then question is:

Are we suppose to use these components in a particular way like: provide fragments (having contents like images, texts, lists etc) to ViewPager Adapter, And set the adapter up with tabs, And finally use view pager to set up the adapter.

Is that all fixed way of assembling/using these components or is there any more to it?

I didn't find any document with diagrams and examples describing it all in one place. Would be great if someone can share. Thanks!

Atul
  • 3,778
  • 5
  • 47
  • 87
  • Take a look at the code in the answer here: http://stackoverflow.com/questions/35967941/whatsapp-like-collapsing-toolbar – Daniel Nugent Apr 12 '16 at 05:07
  • Yes I already been through it :) and to be honest have used part of code as well. But I am doing just more a "code assembling" work now a days. To do something find codes and assemble. Which I don't want to continue. Want to get hold of things so that I can develop fluently the way I was doing on Windows/C++ – Atul Apr 12 '16 at 05:11

1 Answers1

2

Is that all fixed way of assembling/using these components or is there any more to it?

After you go through this, you will realise that View Pagers are basically used for Screen Slides.

This means you can pretty much not integrate your TabLayout with your ViewPager and it would still work, you can still slide fragments from left to right or vice versa.

Yes ViewPagers need Fragments

In android you can show one activity at a time. To show more information on a single screen you need to figure some way out. So you can't have activity inside an activity, thus can't have an activity inside the View Pager; but hey! you can have Fragments since they are not activities and they can hold views together.

If you provide only single fragment in a view pager it would still work.

rusted brain
  • 1,052
  • 10
  • 23