Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.fragment;
- import androidx.appcompat.app.AppCompatActivity;
- import androidx.fragment.app.Fragment;
- import androidx.fragment.app.FragmentManager;
- import androidx.fragment.app.FragmentTransaction;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- public class MainActivity extends AppCompatActivity {
- Button fb1,fb2;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- fb1=findViewById(R.id.fbt);
- fb2=findViewById(R.id.fbt2);
- final Fragment first= new AboutFragment();
- final Fragment second= new MessageFragment();
- fb1.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- FragmentManager fm=getSupportFragmentManager();
- FragmentTransaction fragmentTransaction=fm.beginTransaction();
- fragmentTransaction.replace(R.id.layout,first);
- fragmentTransaction.commit();
- }
- });
- fb2.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- FragmentManager fm=getSupportFragmentManager();
- FragmentTransaction fragmentTransaction=fm.beginTransaction();
- fragmentTransaction.replace(R.id.layout,second);
- fragmentTransaction.commit();
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment