Hello! I am a beginner and I can not figure it out please help. There is a NavigationView and several pages fragment. Problem: for example, I’m in the category snippet and I flip the device and the data is reset and goes to the main screen. How to solve this problem?
OnCreate () code of the main activation:
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout_main); //убрал ненужные коды navigationView.setNavigationItemSelectedListener(this); transaction.beginTransaction().replace(R.id.container, fragment_main).commit(); } and here is the onNavigationItemSelected () method:
switch (item.getItemId()) { case R.id.nav_main : transaction.beginTransaction().replace(R.id.container,fragment_main).commit(); break; case R.id.nav_report_category: transaction.beginTransaction().replace(R.id.container,fragment_category).commit(); break; case R.id.nav_history: transaction.beginTransaction().replace(R.id.container,fragment_history).commit(); break; } DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true; }