Camposha
  • Home
  • Android
  • Buy Projects
  • My Account
    • Become a Member
    • Log In|Log Out
    • Free Projects
No Result
View All Result
Camposha
  • Home
  • Android
  • Buy Projects
  • My Account
    • Become a Member
    • Log In|Log Out
    • Free Projects
No Result
View All Result
Camposha
No Result
View All Result
Home Android Fragment

Fragment Navigation 2.0

2 weeks ago
in Fragment
Reading Time: 1min read
39 1
A A
40
SHARES
4k
VIEWS
Share on FacebookShare on Twitter

Fragment Navigation 2.0 has the following roles:

  1. Navigate between fragments and pass data

It has the following advantages over other similar libraries:

SimilarPosts

Fragment State Manager

2 weeks ago
4k

FragmentRigger

2 weeks ago
4k

Fragment Args

2 weeks ago
4k

Easy-Fragment-Argument

2 weeks ago
4k
  • The transaction logic is in one place.
  • Handles the transaction exception, when the application is in the background.
  • Easy to use and to pass a custom object to the Fragment
DescriptionInfoDownload

Fragment navigator

Android Weekly

Fragment navigator is a simple way to navigate between fragments.

Features

  • The transaction logic is in one place.
  • Handles the transaction exception, when the application is in the background.
  • Easy to use and to pass a custom object to the Fragment(See: FragmentC and FragmentD).
  • The BaseFragmentActivity handles the onBackPressed event. When you want to handle the onBackPressed event inside your Fragment, your Fragment just need to override the OnBackPressed method and write there your navigation code. Note that it has to return true.
  • If you have a navigation drawer in your Activity, after the navigation, the drawer will close automatically if you implement the OnCloseDrawer interface in your Activity. In the onCloseDrawer() method is coming your drawer`s close implementation.
  • If you do not like the navigation implementation(StandardFragmentNavigationStrategy), you can write your own FragmentNavigation behavior.

Implementation steps

  1. Extend your Activity the FragmentActivity class.
  2. Override the getFragmentContainerID method and make it to return your fragment container layout id, which is placed in your activity`s xml.
  3. Extend your Fragments the BaseFragment class.

How to use

public class MainActivity extends FragmentActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        getNavigator().navigateTo(FragmentA.class);
    }

    @Override
    public int getFragmentContainerID() {
        return R.id.fragmentContainer;
    }
}
public class FragmentA extends BaseFragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        final View root = inflater.inflate(R.layout.fragment_a, null);

        root.findViewById(R.id.nextButton).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getNavigator().navigateTo(new FragmentB());
            }
        });
        return root;
    }
}
public class FragmentC extends BaseFragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        View root = inflater.inflate(R.layout.fragment_c, null);

        root.findViewById(R.id.nextButton).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getNavigator().navigateTo(FragmentD.class, new FragmentDBehavior2());
            }
        });
        return root;
    }

    @Override
    public boolean onBackPressed() {
        getNavigator().navigateTo(FragmentB.class);
        return true;
    }
}

You can try it out with the above example or add it to your module level gradle file:

compile 'com.gabor.fragment-navigation:app:1.5.0'
A fragment navigation library
Library written By: gyorgygabor gyorgygabor

Created: 2016-10-18T05:25:59ZLast Update: 2020-04-28T03:13:37Z

Stars: 74Language: JavaForks: 5
View in Github

Download

 

Share16Tweet10Send

Related Posts

Fragment

Fragment State Manager

February 15, 2021
4k
Fragment

FragmentRigger

February 15, 2021
4k
Fragment

Fragment Args

February 15, 2021
4k
Fragment

Easy-Fragment-Argument

February 15, 2021
4k
Activity

CachePot

February 13, 2021
4k

Categories

  • Android
    • Introduction
    • Activity
      • Activity Basics
      • Lifecycle
      • Routing
    • Fragment
    • UI
      • AppBar and Toolbar
      • TextView
      • Tabs
      • Dialog
      • CardView
      • Chips
      • EditText
      • Navigation Drawer
      • Button
      • Bottom Navigation
    • Animation
    • MediaPlayer
      • VideoPlayer
    • Biometric
    • Jetpack
    • Android Firebase
    • Layouts
    • JSON
    • ContentViews
    • RxJava
    • PinView
    • Utility
    • ScrollView
    • URL
    • Log
    • Intent
    • DateTime
    • DownloadManager
    • Camera
    • SharedPreferences
    • SQLite
    • Retrofit
    • RecyclerView
    • Bluetooth
    • Hardware and Sensors
    • HTTP
    • Android AdapterViews
    • Projects
    • InputViews
    • Navigation
    • Menu
    • System
    • Communication
    • HttpURLConnection
    • Fast Networking Library
    • FileSystem
    • Components
    • Threading
    • Local Database
    • Jetpack
  • Flutter
    • Flutter HTTP
    • Flutter Widgets
    • Flutter Firebase
  • Java
    • Java Threading
    • Java Collections
    • JavaFX
  • Programming
  • Flutter Projects
  • Java DateTime
  • Flutter Listing Views
  • Flutter Image
  • Flutter Local Database
  • Documentary
  • Meditation
  • Flutter Animation and Motion
  • Javascript
    • Framework7
  • Xamarin Android
  • Python
    • CherryPy

Get Free Projects

  • Home
  • Android
  • Buy Projects
  • My Account

© 2021 Camposha

No Result
View All Result
  • Account
  • Activate
  • Activity
  • Become a Teacher
  • Become a Teacher
  • Become a Teacher
  • Become instructor
  • Blog
  • Blog
  • Cancel Payment
  • Cancel Payment
  • Cart
  • Change Password
  • Change Password
  • Checkout
  • Checkout
  • Checkout
  • Contact
  • Contact
  • Contact Us
  • Content restricted
  • Course Checkout
  • Dashboard
  • Edit Profile
  • Edit Profile
  • FAQs
  • Forgot Password
  • Forgot Password
  • Guest
  • Guest
  • Home
  • Home
  • Home Light
  • Instructor Dashboard
  • Instructor Registration
  • IUMP – Account Page
  • IUMP – Default Redirect Page
  • IUMP – Login
  • IUMP – LogOut
  • IUMP – Register
  • IUMP – Reset Password
  • IUMP – TOS Page
  • IUMP – Visitor Inside User Page
  • List courses
  • List wish list
  • Login
  • Login
  • Maintenance
  • Members
  • Membership Account
    • Membership Billing
    • Membership Cancel
    • Membership Checkout
    • Membership Confirmation
    • Membership Invoice
    • Membership Levels
  • Membership Account
    • Membership Billing
    • Membership Cancel
    • Membership Checkout
    • Membership Confirmation
    • Membership Invoice
    • Membership Levels
  • Membership Plans
  • My Account
  • OnePage Documentation
  • Portfolio Grid
  • Portfolio Masonry
  • Portfolio Multigrid
  • Privacy Policy
  • Products
  • Profile
  • Profile
  • Profile
  • Projects
  • Register
  • Register
  • Register
  • Register
  • Sample Page
  • Shop
  • Sign in
  • Sign up
  • Student profile
  • Student Registration
  • Thank You
  • Thank You

© 2021 Camposha

Welcome Back!

Login to your account below

Forgotten Password? Sign Up

Create New Account!

Fill the forms below to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In