title: setTitle of collapsing toolbar in other method where it is initialized
body: <p>In my Fragment I have a CollapsingToolbar and it is created it in the <code>onCreateView()</code> method:</p>
  
  <pre><code>@Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
  
  CollapsingToolbarLayout collapsingToolbarLayout = (CollapsingToolbarLayout) getActivity().findViewById(R.id.toolbar_layout);
  AppBarLayout appBarLayout = (AppBarLayout) getActivity().findViewById(R.id.appBar);
  
  return view;
  }
  </code></pre>
  
  <p>Since my title can change in other methods, I tried to create a new method that shall set a new Title of the CollapsingToolbar, but it says <code>cannot resolve symbol 'collapsingToolbarLayout'</code>. I tried it like this:</p>
  
  <pre><code>public void setTitle(String passedTitle){
      collapsingToolbarLayout.setTitle(passedTitle);
  }
  </code></pre>
  
  <p>What do I have to change so I can rename the title from other methods? </p>
  
  <p><strong>Edit:</strong></p>
  
  <p>This is the class where I use the <code>setTitle()</code> method. I try to use it from an inner Class, I tried to cut it as well as possible:</p>
  
  <pre><code>public class CallsFragment extends Fragment {
  
  String title;
  private CollapsingToolbarLayout collapsingToolbarLayout;
  
  public CallsFragment() {
      // Required empty public constructor
  }
  
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      // Inflate the layout for this fragment
      View view = inflater.inflate(R.layout.fragment_calls, container, false);
  
      collapsingToolbarLayout = (CollapsingToolbarLayout) getActivity().findViewById(R.id.toolbar_layout);
      AppBarLayout appBarLayout = (AppBarLayout) getActivity().findViewById(R.id.appBar);
  
      return view;
  }
  
  
  public void setTitle(String passedTitle){
      collapsingToolbarLayout.setTitle(passedTitle);
  }
  
  
  public class GetContacts extends AsyncTask&lt;Void, Void, Void&gt; {
  
      @Override
      protected void onPreExecute() {
          super.onPreExecute();
  
      }
  
      @Override
      protected Void doInBackground(Void... arg0) {
  
      }
  
      @Override
      protected void onPostExecute(Void result) {
          super.onPostExecute(result);
  
      //here the title string gets filled     
              Log.d("place", title);
              setTitle(title);
  }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>And the MainActivity: </p>
  
  <pre><code>public class MainActivity extends AppCompatActivity implements Serializable {
  
  private ViewPager viewPager;
  BottomNavigationView bottomNavigationView;
  ChatFragment chatFragment;
  CallsFragment callsFragment;
  ContactsFragment contactsFragment;
  MenuItem prevMenuItem;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      //Initializing viewPager
      viewPager = (ViewPager) findViewById(R.id.viewpager);
  
      //Initializing the bottomNavigationView
      bottomNavigationView = (BottomNavigationView)findViewById(R.id.bottom_navigation);
  
      bottomNavigationView.setOnNavigationItemSelectedListener(
              new BottomNavigationView.OnNavigationItemSelectedListener() {
                  @Override
                  public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                      switch (item.getItemId()) {
                          case R.id.navigation_umkreis:
                              viewPager.setCurrentItem(0);
                              break;
                          case R.id.navigation_karte:
                              viewPager.setCurrentItem(1);
                              break;
                          case R.id.navigation_einstellungen:
                              viewPager.setCurrentItem(2);
                              break;
                      }
                      return false;
                  }
              });
  
  
      viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
          @Override
          public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
  
          }
  
          @Override
          public void onPageSelected(int position) {
              if (prevMenuItem != null) {
                  prevMenuItem.setChecked(false);
              }
              else
              {
                  bottomNavigationView.getMenu().getItem(0).setChecked(false);
              }
              Log.d("page", "onPageSelected: "+position);
              bottomNavigationView.getMenu().getItem(position).setChecked(true);
              prevMenuItem = bottomNavigationView.getMenu().getItem(position);
  
          }
  
          @Override
          public void onPageScrollStateChanged(int state) {
  
          }
      });
  
  
      setupViewPager(viewPager);
  }
  
  private void setupViewPager(ViewPager viewPager) {
      ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
      callsFragment = new CallsFragment();
      chatFragment = new ChatFragment();
      contactsFragment = new ContactsFragment();
      adapter.addFragment(callsFragment);
      adapter.addFragment(chatFragment);
      adapter.addFragment(contactsFragment);
      viewPager.setAdapter(adapter);
      int limit = adapter.getCount();
      viewPager.setOffscreenPageLimit(limit);
  }
  </code></pre>
  
  <p>}</p>