Question

I want to change the tittle of DrawerLayout from different Fragment.See the senario is that i have a navigation drawer in my app as well as on the home page i have a GridView from which the user can also navigate through the application .So the tittle is getting set properly on click of navigation but on click of the gridview item it is not getting changed how can we do this .

In Fragment Activity

public void onDrawerClosed(View view) {
                getActionBar().setTitle(mTitle);
                invalidateOptionsMenu();
            }  

But how can we set this from the Fragment Class that is Dashboard and the DrawerLayout is in the FragmentActivity.

Was it helpful?

Solution

You can call changeTitle(); method of your MainFragment be following code:

    if(getActivity() instanceof MainFragment){
((MainFragment)getActivity()).changeTitle("new Title")
}

And create changeTitle(String) mehtod in MainFragment:

   public void changeTitle(String newTitle){
getActionBar().setTitle(newTitle);
                invalidateOptionsMenu(); 
}

That is it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top