Sobes.tech
Junior — Middle

Kuidas kuvada ekraanil korraga kahte identset fragmenti?

sobes.tech AI

Vastus AI-lt

To display two identical fragments simultaneously on the screen in Android, you can create two instances of the same fragment class and add them to different containers (e.g., FrameLayout) in the activity's layout.

Example:

// In activity_main.xml layout
// <FrameLayout android:id="@+id/container1" ... />
// <FrameLayout android:id="@+id/container2" ... />

Fragment fragment1 = new MyFragment();
Fragment fragment2 = new MyFragment();

getSupportFragmentManager().beginTransaction()
    .add(R.id.container1, fragment1)
    .add(R.id.container2, fragment2)
    .commit();

This way, two instances of the same fragment will be displayed simultaneously in different parts of the screen.