swayam swayam
swayam swayam

Reputation: 131

How to change header according to navigation drawer

I am using navigation drawer in my application, with fragments. There are icons and text in each row(one of them is products, on clicking these a fragment is open with a list view.After clicking on the list view row i have an activity in this i want header name same as i have selected(products).but bydefault it is showing name off the app which is sales.please help.these are the screen shots

enter image description here

Upvotes: 0

Views: 72

Answers (3)

ErShani
ErShani

Reputation: 392

pass product name in Intent in your list's onItemClickListner

Intent intent = new Intent(getActivity(),YOURACTIVITY.class);
intent.putExtra("product_name",YOUR PRODUCT_NAME);
getActivity().startActivity(intent);

and in your target activity (your product detail activity) put below code in onCreate() method.

getSupportActionBar().setTitle("YOUR DESIRED TITLE");

Upvotes: 2

Sreehari
Sreehari

Reputation: 5655

If using Frament , you can have a method in parent hosting Activity like this

public void setActionBarTitle(String title) {
        getSupportActionBar().setTitle(title);
}

and invoke this method from your individual fragment like this and set the title

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
 //usual statements
 ((HomeActivity)getActivity()).setActionBarTitle("Child fragment name");
}

Upvotes: 1

VinayS
VinayS

Reputation: 11

You can set the actionbar header with the following. You can try this.

ActionBar actionBar = getActionBar(); actionBar.setTitle("My Title");

Upvotes: 0

Related Questions