1

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:

fragment

How can I fix this problem?

gsk
  • 107
  • 11

1 Answers1

0

I found that a mismatch of fragment types created the problem as described in here. I solved the problem by following the steps here. Hope this helps someone in the same situation that I was in.

gsk
  • 107
  • 11