1

I'm trying to understand how viewpager works by breaking down the source and I got to the dataSetChanged method. I got to the dataSetChanged method and within it is this piece of code.

if (needPopulate) {
     // Reset our known page widths; populate will recompute them.
     final int childCount = getChildCount();
     for (int i = 0; i < childCount; i++) {
          final View child = getChildAt(i);
          final LayoutParams lp = (LayoutParams) child.getLayoutParams();
          if (!lp.isDecor) {
              lp.widthFactor = 0.f;
          }
     }
}

I was wondering what is it that getChildCount() returns when it is called. I understand that it is a ViewGroup method and returns all the children of the Viewgroup calling the method but in this instance would the method return 1 for the FragmentStatePagerAdapter that I will be adding or does it return the number of pages within my FragmentStatePagerAdapter? What is the best way to find out?

Samuel Robert
  • 10,106
  • 7
  • 39
  • 60
  • Why don't you just debug your code ? – Neeraj Nov 07 '17 at 05:53
  • I guess that's what I'm trying to figure out. How do you debug the classes that come from android? Sorry if this is a very amateur question. – Nestor Cortes Nov 07 '17 at 06:07
  • you'll need to download the sources in SDK manager – Neeraj Nov 07 '17 at 06:21
  • I think I did. That's the way I was trying to decompose the viewpager source. I had to manually navigate to ~/Library/Android/...etc. to look at the source. I know there is an easier way using the debug tools in Android Studio but I just haven't reached that point yet. I was hoping to get there with this post. – Nestor Cortes Nov 07 '17 at 06:27
  • If you have the source then while debugging your app you should be able to step into the source code. Check this : https://stackoverflow.com/a/36903786/1630255 – Neeraj Nov 07 '17 at 06:32
  • Awesome, I think that gives me what I'm looking for. I'll come back and answer my own question now that I can follow exactly what it is doing. Thank you @Neeraj – Nestor Cortes Nov 07 '17 at 06:46
  • For my case getChildCount() was 2. It created two children. prior to getting to this method. – Nestor Cortes Nov 16 '17 at 02:48

0 Answers0