title: Change FloatingActionButton from a Fragment in a Tabbed Activity
body: <p>How are you ? 
  I am new in android programming. I am facing an issue that I have tried to handle. But, I couldn't. 
  I have created a new project. Tabbed Activity. </p>
  
  <p>I have changed some of it's settings. 
  For each tab, I create a fragment.
  I kept the default floatingActionButton in the MainActity Layout. 
  I tried to access it from a fragment. </p>
  
  <p>An error arises.
  Here are my MainActivity class: </p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  private SectionsPagerAdapter mSectionsPagerAdapter;
  private ViewPager mViewPager;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);
      getSupportActionBar().setDisplayHomeAsUpEnabled(true);
      // Create the adapter that will return a fragment for each of the three
      // primary sections of the activity.
      mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
      mViewPager = (ViewPager) findViewById(R.id.container);
      mViewPager.setAdapter(mSectionsPagerAdapter);
  
      TabLayout tabLayout = (TabLayout) findViewById(R.id.Main_FAB);
  
      mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
      tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager));
  
  
  }
  
  public class SectionsPagerAdapter extends FragmentPagerAdapter {
      public SectionsPagerAdapter(FragmentManager fm) {
          super(fm);
      }
  
      @Override
      public Fragment getItem(int position) {
          switch (position)
          {
              case 0 : Summary summary = new Summary(); return summary ;
              case 1 : Expense_items expenseItems = new Expense_items(); return expenseItems;
              case 2 : Linage_items linage_items= new Linage_items(); return linage_items;
              default: return null;
          }
      }
  
      @Override
      public int getCount() {
          // Show 3 total pages.
          return 3;
      }
  }
  }
  </code></pre>
  
  <p>my Summary fragment as the followings: </p>
  
  <pre><code>public class Summary extends Fragment {
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      View rootView = inflater.inflate(R.layout.fragment_summary, container, false);
      TextView summary_text = (TextView) rootView.findViewById(R.id.summary_text);
      summary_text.setText("You are in Summary Fragment Fragment");
      FloatingActionButton myFB  = (FloatingActionButton) rootView.findViewById(R.id.fab);
  
      return rootView;
  }
  }
  </code></pre>
  
  <p>In my MainActivity layout I created the floatingActionButton as the followings:</p>
  
  <pre><code>&lt;android.support.design.widget.FloatingActionButton
      android:id="@+id/Main_FAB"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_gravity="end|bottom"
      android:layout_margin="@dimen/fab_margin"
      app:srcCompat="@android:drawable/ic_dialog_email" /&gt;
  </code></pre>
  
  <p>The reason I don't want to create a FloatingActionButton in my Fragments is because I don't want to change the location of it in the layout. </p>