findfragmentbyid returns null in mainActivity hosting 3 fragments under a viewpager
<p>I am trying to write different functionalities for my FloatingActionButton depending on the fragment that the mainActivity is currently hosting. Yet for for reason in my <code>onClick()</code> method, <code>getSupportFragmentManager().findFragmentById()</code> returns <code>null</code>. </p>

<p>I haven't seen any examples of this question implemented with a viewpager and I am curious if there is a different approach I have to take. </p>

<pre><code> MainActivity

    import android.content.Intent;
    import android.os.Bundle;
    import android.support.design.widget.FloatingActionButton;
    import android.support.v4.app.Fragment;
    import android.support.v4.app.FragmentActivity;
    import android.support.v4.view.ViewPager;
    import android.util.Log;
    import android.view.View;


    public class MainActivity extends FragmentActivity {

    private Adapter mAdapter;
    private ViewPager mViewPager;
    private static FloatingActionButton bButton;
    private static String UID;
    private Intent intent;


    public static String getUID(){
        return UID;
    }



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mAdapter = new Adapter(getSupportFragmentManager());
        mViewPager = (ViewPager)findViewById(R.id.vPager);
        mViewPager.setAdapter(mAdapter);

        intent = getIntent();
        UID = intent.getStringExtra("uid");

        bButton = (FloatingActionButton)findViewById(R.id.bButton);
        bButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragContainer);

                if(fragment == null){

                    Log.e("TAG","FRAGMENT IS NULL!!");
                }
                else{
                    Log.e("TAG","FRAGMENT IS NOT NULL!!");

                }

              }

           });
      }
     }


NewsFeedFragment


    import android.os.Bundle;
    import android.support.v4.app.FragmentManager;
    import android.support.v4.app.ListFragment;
    import android.util.Log;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.AdapterView;
    import android.widget.ArrayAdapter;
    import android.widget.ListView;
    import android.widget.TextView;
    import android.widget.Toast;

    import com.firebase.client.Firebase;
    import com.firebase.client.FirebaseError;
    import com.mycompany.neighbors.R;
    import com.mycompany.neighbors.SinglePost;

    import java.util.ArrayList;

    /**
     * Created by joshua on 5/25/2016.
     */
    public class NewsFeedFragment extends ListFragment implements AdapterView.OnItemClickListener{

        private ListView lv;
        private TextView tvUserName;
        private TextView tvStatus;
        private ArrayList&lt;SinglePost&gt; posts = new ArrayList&lt;&gt;();
        private static final String POSTS_PATH = "MY_PATH";
        private Firebase postsRef;
    //    private static final String FRAGMENT_POST = "post";


        public void postFragment(){
            Log.d("TAG", "Doing something else");

            PostFragment postFragment = new PostFragment();
            FragmentManager fragmentManager = getFragmentManager();
            fragmentManager.beginTransaction()
                    .replace(R.id.fragContainer,postFragment)
                    .addToBackStack(null)
                    .commit();
        }

        @Override
        public void onViewCreated(View v, Bundle s){

            lv =  getListView();
            lv.setOnItemClickListener(this);

        }

        @Override
        public void onCreate(Bundle savedInstance){
            super.onCreate(savedInstance);

        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState){

            View v = inflater.inflate(R.layout.fragment_post_feed_item,parent,false);//changed

            tvUserName = (TextView)v.findViewById(R.id.tvUN);
            tvStatus = (TextView)v.findViewById(R.id.tvStatus);

            postsRef = new Firebase(POSTS_PATH);
            postsRef.addChildEventListener(new com.firebase.client.ChildEventListener() {
                @Override
                public void onChildAdded(com.firebase.client.DataSnapshot dataSnapshot, String s) {

                    SinglePost post = dataSnapshot.getValue(SinglePost.class);
                    post.setKey(dataSnapshot.getKey());
                    posts.add(0, post);

                    if(posts.size() &gt; 0) {
                        PostAdapter adapter = new PostAdapter(posts);
                        setListAdapter(adapter);
                    }else{
                        Toast toast = Toast.makeText(getActivity(),"No data", Toast.LENGTH_SHORT);
                        toast.show();
                    }

                }

                @Override
                public void onChildChanged(com.firebase.client.DataSnapshot dataSnapshot, String s) {

                }

                @Override
                public void onChildRemoved(com.firebase.client.DataSnapshot dataSnapshot) {

                }

                @Override
                public void onChildMoved(com.firebase.client.DataSnapshot dataSnapshot, String s) {

                }

                @Override
                public void onCancelled(FirebaseError firebaseError) {

                }
            });


            return v;
        }

        @Override
        public void onListItemClick(ListView l, View v, int position, long id){

            SinglePost p = ((PostAdapter) getListAdapter()).getItem(position);

        }

        @Override
        public void onItemClick(AdapterView&lt;?&gt; adapterView, View view, int i, long l) {

        }

        private class PostAdapter extends ArrayAdapter&lt;SinglePost&gt;{

           public PostAdapter(ArrayList&lt;SinglePost&gt; singlePost){
               super(getActivity(),android.R.layout.simple_list_item_1,singlePost);
           }

            @Override
            public View getView(int position, View convertView, ViewGroup parent){

                if(convertView == null){
                    convertView = getActivity().getLayoutInflater().inflate(R.layout.fragment_post_feed_item,null);

                }

                SinglePost p = getItem(position);

                TextView tvUserName = (TextView)convertView.findViewById(R.id.tvUN);
                tvUserName.setText(p.getUserName());

                TextView tvStatus = (TextView)convertView.findViewById(R.id.tvStatus);
                tvStatus.setText(p.getStatus());



                return convertView;
            }

        }
    }

I have 2 other fragments but i'll post one as an example. Here is my adapter for the viewpager.

Adapter

    import android.support.v4.app.Fragment;

    import android.support.v4.app.FragmentManager;
    import android.support.v4.app.FragmentPagerAdapter;

    import com.mycompany.neighbors.Fragments.MapFragment;
    import com.mycompany.neighbors.Fragments.NewsFeedFragment;
    import com.mycompany.neighbors.Fragments.ProfileFragment;

    /**
     * Created by joshua on 5/25/2016.
     */
    public class Adapter extends FragmentPagerAdapter {


            private String Fragment[] = {"Posts" , "Map" , "Profile"};
            public Adapter(FragmentManager fm){
                super (fm);
            }


            @Override
            public Fragment getItem(int position) {
                switch(position){
                    case 0:
                        return new NewsFeedFragment();
                    case 1:
                        return new MapFragment();
                    case 2:
                        return new ProfileFragment();

                    default:
                        return null;
                }

            }

            @Override
            public int getCount(){return Fragment.length;}

            @Override
            public CharSequence getPageTitle(int position) {
                return Fragment[position];
            }

        }
</code></pre>