Created
November 1, 2020 15:59
-
-
Save Mushahid2521/0938bde76f022a5f9dcaf2c43af62f3c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends AppCompatActivity{ | |
final FragmentManager fragmentManager = getSupportFragmentManager(); | |
Fragment active_fragment; | |
SongsFragment songs_fragment; | |
ArtistsFragment artists_fragment; | |
AlbumsFragment albums_fragment; | |
@Override | |
protected final void onCreate(@NonNull Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.seller_activity); | |
songs_fragment = new SellerProducts(); | |
fragmentManager.beginTransaction().add(R.id.container, songs_fragment, "Songs").commit(); | |
active_fragment = songs_fragment; | |
} | |
private final BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener | |
= item -> { | |
switch (item.getItemId()) { | |
case R.id.songs: | |
if(fragmentManager.findFragmentByTag("Songs")==null) { | |
songs_fragment = new SellerProducts(); | |
fragmentManager.beginTransaction().add(R.id.container, songs_fragment, "Songs").hide(songs_fragment).commit(); | |
} | |
fragmentManager.beginTransaction().hide(active_fragment).show(songs_fragment).commit(); | |
active_fragment = sellerShop_fragment; | |
return true; | |
case R.id.artists: | |
if(fragmentManager.findFragmentByTag("Artists")==null) { | |
artists_fragment = new ArtistsFragment(); | |
fragmentManager.beginTransaction().add(R.id.container, artists_fragment, "Artists").hide(artists_fragment).commit(); | |
} | |
fragmentManager.beginTransaction().hide(active_fragment).show(artists_fragment).commit(); | |
active_fragment = artists_fragment; | |
return true; | |
case R.id.albums: | |
if(fragmentManager.findFragmentByTag("Albums")==null) { | |
albums_fragment = new AlbumsFragment(); | |
fragmentManager.beginTransaction().add(R.id.container, albums_fragment, "Orders").hide(albums_fragment).commit(); | |
} | |
fragmentManager.beginTransaction().hide(active_fragment).show(albums_fragment).commit(); | |
active_fragment = albums_fragment; | |
return true; | |
} | |
return false; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment