import
android.os.Bundle;
import
androidx.appcompat.app.AppCompatActivity;
import
androidx.fragment.app.Fragment;
import
com.google.android.material.bottomnavigation.BottomNavigationView;
public
class
MainActivity
extends
AppCompatActivity {
@Override
protected
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
BottomNavigationView bottomNav = findViewById(R.id.bottom_navigation);
bottomNav.setOnNavigationItemSelectedListener(navListener);
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
new
AlgorithmFragment()).commit();
}
private
final
BottomNavigationView.OnNavigationItemSelectedListener navListener = item -> {
Fragment selectedFragment =
null
;
int
itemId = item.getItemId();
if
(itemId == R.id.algorithm) {
selectedFragment =
new
AlgorithmFragment();
}
else
if
(itemId == R.id.course) {
selectedFragment =
new
CourseFragment();
}
else
if
(itemId == R.id.profile) {
selectedFragment =
new
ProfileFragment();
}
if
(selectedFragment !=
null
) {
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, selectedFragment).commit();
}
return
true
;
};
}