it can be a reset toolbar. Not from MainActivity?

public class MainActivity extends AppCompatActivity { public Toolbar toolbar; toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar.setTitle(R.string.app_name); 

And i want to change the title from TabAdapter.class. How can I do it? When I'm trying to do it, I'm getting a nullpointerexception.

 public class TabAdapter extends FragmentPagerAdapter{ MainActivity main = new MainActivity(); @Override public Fragment getItem(int position) { switch (position){ case 0: return MainFragment.getInstance(); case 1: main.toolbar.setTitle("hello world"); return SearchFragment.getInstance(); } return null; } 
  • Do you speak russian? If answer is "no", use enSO - Denis
  • Well, in general, I speak Russian too - Ilya Kulikov
  • @IlyaKulikov, in this case it is necessary to translate the question into Russian, because we are SO in Russian) - YuriySPb
  • And you are not embarrassed that this ru. stackoverflow.com and is everything in Russian?) - Denis

1 answer 1

  1. You need to send a link to the activation in the adapter (through the constructor, for example).
  2. After that you can find your toolbar by ID and change it.

Now you are creating an instance of an actviti class, which is not a valid activator and is not used anywhere at all and is not displayed.