Итак, моя заявка начинается здесь:"https://i.stack.imgur.com/Y4e0d.jpg"
Скажите, что я хочу пойти в мои поездки, я нажимаю на нее, а затем получаю это: "https://i.stack.imgur.com/tOWLW.jpg"
Затем пользователь хочет перейти к сообщениям: " https://i.stack.imgur.com/PfY9W.jpg"
И затем, если пользователь возвращается в мои поездки, но этоне работает."https://i.stack.imgur.com/SBZhH.jpg"
Вот код, который я использую:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_trips, container, false);
navigationBar = view.findViewById(R.id.TopMenu);
mainFrameLayout = view.findViewById(R.id.resultFrame);
posts = new Posts();
map = new Maps();
myTrips = new myTrips();
getChildFragmentManager().beginTransaction().replace(R.id.resultFrame, posts).commit();
navigationBar.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
switch (menuItem.getItemId())
{
case R.id.nav_Posts:
getChildFragmentManager().beginTransaction().replace(R.id.resultFrame, posts).commit();
return true;
case R.id.nav_Maps:
getChildFragmentManager().beginTransaction().replace(R.id.resultFrame, map).commit();
return true;
case R.id.nav_myTrips:
getChildFragmentManager().beginTransaction().replace(R.id.resultFrame, myTrips).commit();
return true;
default:
return true;
}
}
});
return view;
Вот где код нижнего меню:
private FirebaseUser currentUser;
private BottomNavigationView navigationBar;
private FrameLayout mainFrameLayout;
private tripsFragment tripsFragment;
private messagesFragment messagesFragment;
private notificationFragment notificationFragment;
private profileFragment profileFragment;
private int LastFragment;
@Override
public void onBackPressed() {
if(LastFragment != tripsFragment.getId())
{
getSupportFragmentManager().beginTransaction().replace(LastFragment, tripsFragment).commit();
navigationBar.getMenu().getItem(0).setChecked(true);
}
else{
super.onBackPressed();
finishAffinity();
finish();
}
}
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_screen);
currentUser = FirebaseAuth.getInstance().getCurrentUser();
if(currentUser != null){
boolean emailVerified = currentUser.isEmailVerified();
if(emailVerified == false){
Toast.makeText(MainScreen.this, "Email is not verified yet.", Toast.LENGTH_LONG).show();
}
}
navigationBar = findViewById(R.id.navigationBar);
mainFrameLayout = findViewById(R.id.mainFrameLayout);
tripsFragment = new tripsFragment();
messagesFragment = new messagesFragment();
notificationFragment = new notificationFragment();
profileFragment = new profileFragment();
getSupportFragmentManager().beginTransaction().replace(R.id.mainFrameLayout, tripsFragment).commit();
LastFragment = tripsFragment.getId();
navigationBar.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
switch (menuItem.getItemId())
{
case R.id.nav_Trips:
getSupportFragmentManager().beginTransaction().replace(R.id.mainFrameLayout, tripsFragment).commit();
LastFragment = tripsFragment.getId();
return true;
case R.id.nav_Notifications:
getSupportFragmentManager().beginTransaction().replace(R.id.mainFrameLayout, notificationFragment).commit();
LastFragment = notificationFragment.getId();
return true;
case R.id.nav_Messages:
getSupportFragmentManager().beginTransaction().replace(R.id.mainFrameLayout, messagesFragment).commit();
LastFragment = messagesFragment.getId();
return true;
case R.id.nav_Profile:
getSupportFragmentManager().beginTransaction().replace(R.id.mainFrameLayout, profileFragment).commit();
LastFragment = profileFragment.getId();
return true;
default:
return false;
}
}
});
}