Skip to content

In the context of programming, especially in mobile app development or other software applications, passing data from one fragment to another is a common requirement. Fragments are components of an activity in Android, for example, and sometimes you need to send information from one fragment to another.

Notifications You must be signed in to change notification settings

sakibul4hasan/DataPassing-in-Fragment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 

Repository files navigation

FragmentToFragment-DataPass

In the context of programming, especially in mobile app development or other software applications, passing data from one fragment to another is a common requirement. Fragments are components of an activity in Android, for example, and sometimes you need to send information from one fragment to another.

Here's a brief overview of how you can pass data from one fragment to another in Android using bundles:

Sending Data from Fragment A to Fragment B:

// In Fragment A
Bundle bundle = new Bundle();
bundle.putString("key", "value"); // You can put any type of data in the bundle

FragmentB fragmentB = new FragmentB();
fragmentB.setArguments(bundle);

getFragmentManager().beginTransaction()
    .replace(R.id.fragment_container, fragmentB)
    .addToBackStack(null)
    .commit();

Receiving Data in Fragment B:

// In Fragment B
Bundle bundle = getArguments();
if (bundle != null) {
    String value = bundle.getString("key");
    // Do something with the received data
}

Remember to replace R.id.fragment_container with the actual ID of the container where your fragments are being displayed.

About

In the context of programming, especially in mobile app development or other software applications, passing data from one fragment to another is a common requirement. Fragments are components of an activity in Android, for example, and sometimes you need to send information from one fragment to another.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published