How do I stop overlapping clips on direction changes?
•
Android
I have an application that uses fragments to display data. The main activities shown below control the fragments with recyclerview inside. When I change the direction, I look like one recyclerview overlaps another. Each time the direction changes, another fragment will be created. How can I solve it? Any help would be great
public class MainActivity extends AppCompatActivity
implements NotesFragment.OnFragmentInteractionListener, EditFragment.SaveFragmentItem {
EditFragment editFrag;
NotesFragment notesFrag;
FragmentManager fragmentManager;
FragmentTransaction fragmentTransaction;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
notesFrag = new NotesFragment();
editFrag = new EditFragment();
fragmentManager = getSupportFragmentManager();
fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.container1, notesFrag);
fragmentTransaction.commit();
}
....
}
resolvent:
I know what happened. This is an offensive line of code:
fragmentTransaction.add(R.id.container1, notesFrag);
Instead of adding another instance of the fragment to the fragmentmanager, I need to use the replace () method to replace the fragment after each direction change
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码