Sajib_Ahmed

Fragment

Mar 10th, 2021
547
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.54 KB | None | 0 0
  1. package com.example.fragment;
  2.  
  3. import androidx.appcompat.app.AppCompatActivity;
  4. import androidx.fragment.app.Fragment;
  5. import androidx.fragment.app.FragmentManager;
  6. import androidx.fragment.app.FragmentTransaction;
  7.  
  8. import android.os.Bundle;
  9. import android.view.View;
  10. import android.widget.Button;
  11.  
  12. public class MainActivity extends AppCompatActivity {
  13.  
  14.     Button fb1,fb2;
  15.     @Override
  16.     protected void onCreate(Bundle savedInstanceState) {
  17.         super.onCreate(savedInstanceState);
  18.         setContentView(R.layout.activity_main);
  19.         fb1=findViewById(R.id.fbt);
  20.         fb2=findViewById(R.id.fbt2);
  21.         final Fragment first= new AboutFragment();
  22.         final Fragment second= new MessageFragment();
  23.         fb1.setOnClickListener(new View.OnClickListener() {
  24.             @Override
  25.             public void onClick(View view) {
  26.  
  27.                 FragmentManager fm=getSupportFragmentManager();
  28.                 FragmentTransaction fragmentTransaction=fm.beginTransaction();
  29.                 fragmentTransaction.replace(R.id.layout,first);
  30.                 fragmentTransaction.commit();
  31.             }
  32.         });
  33.         fb2.setOnClickListener(new View.OnClickListener() {
  34.             @Override
  35.             public void onClick(View view) {
  36.  
  37.                 FragmentManager fm=getSupportFragmentManager();
  38.                 FragmentTransaction fragmentTransaction=fm.beginTransaction();
  39.                 fragmentTransaction.replace(R.id.layout,second);
  40.                 fragmentTransaction.commit();
  41.             }
  42.         });
  43.  
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment