I am trying to move from an activity named MyNotes.java
to one fragment named FragmentNotes.java
. I found that the following codes should be used to perform the movement:
Fragment mFragmentNotes = new FragmentNotes ();
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragment_note_id, mFragmentNotes).addToBackStack(null);
fragmentTransaction.commit();
And I think R.id.fragment_note_id
should be the id of the fragment's layout. (BTW, I am curious why I need to "replace" the id of the fragment's layout when I am simply moving back to the fragment.) However, the above codes do not work, making mFragmentNotes
with a red line as follows:
How can I fix this problem?