0% found this document useful (0 votes)
5 views

MainActivity Java

Uploaded by

lowlevel269
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

MainActivity Java

Uploaded by

lowlevel269
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

package com.example.

smstaxorv2;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.navigation.NavigationBarView;

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.setSelectedItemId(R.id.nav_home);
bottomNav.setOnItemSelectedListener(navListener);

Fragment selectedFragment = new Home_FRG();

getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
selectedFragment).commit();

private final NavigationBarView.OnItemSelectedListener navListener =


item -> {
int itemId = item.getItemId(); /* obtain the selected item ID from
your source */
Fragment selectedFragment = null;

if (itemId == R.id.nav_home) {
selectedFragment = new Home_FRG();
} else if (itemId == R.id.nav_chat) {
selectedFragment = new Token_FRG();
} else if (itemId == R.id.nav_profile) {
// Handle the profile case
selectedFragment = new Profile_FRG();

} else if (itemId == R.id.nav_chat) {


// Handle the profile case
selectedFragment = new Chat_FRG();
}else {
selectedFragment = new Home_FRG();
}

getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
selectedFragment).commit();
return true;
};

You might also like