title: Check if fragment is currently visible or no
body: <p>I know there are lots of similar questions in StackOverflow but my question is little different.</p>
  
  <p>I have nested hierarchy of Fragments like in below structure:</p>
  
  <pre><code>                                  Activity
                                       |
                                       |
                                   AFragment
                                       |
                                  (ViewPager)
                                   |       |         
                                   |       |         
                           BFragment       BFragment  .....
                              |                       
                         (ViewPager)                       
                          |       |                         
                          |       |                         
                   CFragment     CFragment  ...
                       |
                  (ViewPager)                       
                    |     |                              
                    |     |                        
             DFragment   DFragment ...
  </code></pre>
  
  <p>Now i want to know that whether <code>DFragment</code> is showing to user or not?</p>
  
  <p>I tried lots of solution from StackOverflow but couldn't get sucess. </p>
  
  <p><strong>What i tried is:</strong></p>
  
  <p>I tried <code>setUserVisibleHint()</code> but it returns <code>true</code>for multiple <code>DFragment</code> in above hierarchy which is a cause of <code>ViewPager</code></p>
  
  <p>I also tried from these links: <a href="https://stackoverflow.com/questions/10024739/how-to-determine-when-fragment-becomes-visible-in-viewpager">link1</a>, <a href="https://stackoverflow.com/questions/9323279/how-to-test-if-a-fragment-view-is-visible-to-the-user">link2</a>, <a href="https://stackoverflow.com/questions/16221195/determine-which-fragment-currently-visible-in-viewpager">link3</a> and so on... but did not got actual solution.</p>
  
  <p>Waiting for help. Thank you.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p><strong>Adapter Class</strong></p>
  
  <pre><code>class ViewPagerAdapter extends FragmentPagerAdapter {
          private final List&lt;Fragment&gt; mFragmentList = new ArrayList&lt;&gt;();
          private final List&lt;String&gt; mFragmentTitleList = new ArrayList&lt;&gt;();
  
          public ViewPagerAdapter(FragmentManager manager) {
              super(manager);
          }
  
          @Override
          public Fragment getItem(int position) {
              return mFragmentList.get(position);
          }
  
          @Override
          public int getCount() {
              return mFragmentList.size();
          }
  
          public void addFragment(Fragment fragment, String title) {
              mFragmentList.add(fragment);
              mFragmentTitleList.add(title);
          }
  
          @Override
          public CharSequence getPageTitle(int position) {
              return mFragmentTitleList.get(position);
          }
      }
  </code></pre>