I'm working on an Android project and I'm trying to override a method from a parent class. I still want the method to work all the same, only thing is that I need to add one more line. This is the method in my BaseFragment:
protected void setUpToolBar(String title, boolean home){
Toolbar toolbar = (Toolbar)getView().findViewById(R.id.toolbar);
if (toolbar != null){
toolbar.setTitle(title);
if(home){
toolbar.setNavigationIcon(R.drawable.arrow_left);
}
toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
return false;
}
});
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
((AppCompatActivity)getActivity()).setSupportActionBar(toolbar);
}
}
I want to keep all the stuff working when I call from my FeedFragment (which extends from BaseFragment) and add this line:
toolbar.inflateMenu(R.menu.menu_main);
I need that because the menu on FeedFragment is different from the one on PostFragment and both fragments inherit from BaseFragment.
I think I should do something like:
@Override
private void setUpToolBar(){
toolbar.inflateMenu();
}
It's not working though. Any ideas on this?
obs: this question was marked as a possible duplicate but the other one is quite theoretical and I don't think it would help me to figure out how to solve my problem. the chosen answer just hit the nail on the head.