I made a layout using Bottom Navigation View
I made it with three fragments.
The problem is that each item has a list view.
Move each item and come back, not where you were viewing the list view
to the top of the list view
I want to keep the position I saw even if I move each item, is it possible?
The sauce is as follows
Thank you^
^private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= = new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item)
{
Fragment selectedFragment = null;
switch (item.getItemId()) {
case R.id.navigation_home:
selectedFragment = MainFragment.newInstance();
break;
case R.id.navigation_dashboard:
selectedFragment = SencondFragment.newInstance();
break;
case R.id.navigation_notifications:
selectedFragment = ThirdFragment.newInstance();
break;
}
if(selectedFragment != null)
{
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.frame_layout, selectedFragment);
transaction.commit();
}
return true;
}
};
Because replace() acts as remove() -> add(), the scroll position is initialized by regenerating the Fragment instance. Therefore, it is necessary to use hide(), show(), or save the value and reload it.
© 2024 OneMinuteCode. All rights reserved.