Something strange is happening..!
So I have an activity with TextView in the center of the toolbar acting as toolbar title, once the activity gets launched, I commit the MainFragment or let's name it Fragment (A)
.
- Inside Fragment (A), I replace it with Fragment (B) when a button gets clicked.
- Inside Fragment (B), I replace it with Fragment (C) when a button gets clicked.
so in each fragment I access the activity's toolbar text view and change it accordingly using this:
TextView title = getActivity().findViewById(R.id.titleText);
title.setText("Some title");
And it works fine in Fragments (A) & (B), but in (C) it shows the title of Fragment (A)?? I even printed a log inside the onCreateView of each fragment and this is what showed up..!
the last two logs showed at the same time..!?
I/MY_TEST: onCreateView: of Fragment (A)
I/MY_TEST: onCreateView: of Fragment (B)
I/MY_TEST: onCreateView: of Fragment (C)
I/MY_TEST: onCreateView: of Fragment (A)
Update
Here's the full click listener
orderDetailsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AppCompatActivity activity = (AppCompatActivity) getActivity();
Fragment fragment = new Teacher_Bar_Fragment();
Bundle bundle = new Bundle();
bundle.putInt("index", 1); // I use this to show or hide views
fragment.setArguments(bundle);
FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction();
ft.replace(R.id.fragment_container, fragment);
ft.addToBackStack(null);
ft.commit();
}
});