I'm a beginner, and I don't understand, please help. I have the NavigationView and several page fragments. The Problem: If I change the orientation to landscape then reset the data it moves to the main screen. How do you solve this problem?
Code MainActivity.Oncreate()
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_main);
//removed unnecessary codes
navigationView.setNavigationItemSelectedListener(this);
transaction.beginTransaction().replace(R.id.container, fragment_main).commit();
}
and void onNavigationItemSelected() of navigationview
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;