Communicate between fragments and layouts












0















I don't really know how to ask this question but I will start off with the idea here.



So I have a MainFragment that contains a SlidingUpPanelLayout that includes a viewpager and a layout that hold the controls for the application.



And what I want to do is when I change between fragments in the tablayout I want to change the layout of that holds the controls, I also want to trigger functions from the fragment with the controls in on my different fragments in the viewpager.



But since they are in different fragments I don't know how to get the control layouts and buttons to change and get a hold of them.



So here is first an image of the layout:
https://imgur.com/a/SgdI21L



And here is how my following XML looks like:
XML for the Control Content:



<LinearLayout android:id="@+id/control"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#000"
android:clickable="false"
android:gravity="center|top"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@color/controlBackground"
app:tabGravity="fill"
app:tabIndicatorColor="@color/colorText"
app:tabMode="scrollable"
app:tabSelectedTextColor="@color/colorAccent"
app:tabTextColor="@color/colorText">
</android.support.design.widget.TabLayout>

<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<android.support.design.widget.FloatingActionButton
android:id="@+id/takePicture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|center_vertical"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:backgroundTint="@color/colorText"
android:clickable="true" />

<ImageButton
android:id="@+id/flipCamera"
style="@android:style/Widget.Material.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|left"
android:padding="20dp"
android:clickable="true"
android:tint="@color/colorText"
android:backgroundTint="@color/colorText"
android:src="@drawable/ic_outline_camera_front_24px" />

<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/openGallery"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="center|right"
android:padding="20dp"
android:src="@drawable/fox"
android:clickable="true"
app:civ_border_color="#FF000000"
app:civ_border_width="2dp" />

</android.support.design.widget.CoordinatorLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center|top"
android:padding="10dp"
android:text="Pete is king!"
android:layout_gravity="center"
android:textColor="@color/colorText"
android:textSize="16sp" />

<ImageButton
android:id="@+id/info"
style="@android:style/Widget.Material.Button.Borderless"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|end"
android:layout_weight="1"
android:padding="20dp"
android:clickable="true"
android:backgroundTint="@color/colorAccent"
android:tint="@color/colorAccent"
android:src="@drawable/ic_shutterowl_24dp" />

</LinearLayout>
</LinearLayout>


And here is my viewpager:



<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<owlapps.shutterowl.AutoFitTextureView
android:id="@+id/texture"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_toEndOf="@+id/control"
xmlns:android="http://schemas.android.com/apk/res/android" />
</android.support.v4.view.ViewPager>


They are all showed together in a SlideUpPanelLayout like so:



<com.sothree.slidinguppanel.SlidingUpPanelLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
xmlns:sothree="http://schemas.android.com/apk/res-auto"
sothree:layout_constraintHeight_max="80dp"
sothree:umanoPanelHeight="120dp"
sothree:umanoShadowHeight="0dp"
sothree:umanoOverlay="true">

<include layout="@layout/camera_content"/>

<include layout="@layout/control_content"/>


</com.sothree.slidinguppanel.SlidingUpPanelLayout>


I had an idea to solve this with a interface that could trigger functions from the MainFragment that loads the camera and content layouts, here is what i tried:



In a click event from the mainfragment: Tab1Fragment.take.visible(true);



My interface looks like this:



public interface CameraControlListener {
void visible(boolean status);
}


And is implemented in the Tab1Fragment that holds the camera view:



@Override
public void visible(boolean status) {
if(status){
takePicture();
}
}


So how can I get all these to speak with eachother?
As i move between fragments i want the controls to change that are inside another fragment and also trigger functions from the active tabfragment in the viewpager.










share|improve this question























  • The activity holding all these fragments should be coordinating the communication. The fragments should never directly communicate.

    – Greg Moens
    Nov 25 '18 at 14:47











  • Ok. I tried from the mainactivity to get hold of objects in the other fragment but did get a null pointer exception since the items are in different fragments.

    – Major Bronco
    Nov 25 '18 at 22:27











  • Did you go through FragmentManager and use findFragmentById() or findFragmentByTag()?

    – Greg Moens
    Nov 25 '18 at 23:43











  • Can I really use fragmentmanager since the XML in the layout is not a fragment or should I just change it to a fragment instead of linearlayout

    – Major Bronco
    Nov 27 '18 at 16:03











  • You can use FragmentManager to get a hold of a fragment if the fragment was added with an ID or tag. If you want a change to the active fragment in a view pager to trigger other behavior, you probably want to attach an OnPageChangeListener to the pager.

    – Greg Moens
    Nov 27 '18 at 20:00
















0















I don't really know how to ask this question but I will start off with the idea here.



So I have a MainFragment that contains a SlidingUpPanelLayout that includes a viewpager and a layout that hold the controls for the application.



And what I want to do is when I change between fragments in the tablayout I want to change the layout of that holds the controls, I also want to trigger functions from the fragment with the controls in on my different fragments in the viewpager.



But since they are in different fragments I don't know how to get the control layouts and buttons to change and get a hold of them.



So here is first an image of the layout:
https://imgur.com/a/SgdI21L



And here is how my following XML looks like:
XML for the Control Content:



<LinearLayout android:id="@+id/control"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#000"
android:clickable="false"
android:gravity="center|top"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@color/controlBackground"
app:tabGravity="fill"
app:tabIndicatorColor="@color/colorText"
app:tabMode="scrollable"
app:tabSelectedTextColor="@color/colorAccent"
app:tabTextColor="@color/colorText">
</android.support.design.widget.TabLayout>

<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<android.support.design.widget.FloatingActionButton
android:id="@+id/takePicture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|center_vertical"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:backgroundTint="@color/colorText"
android:clickable="true" />

<ImageButton
android:id="@+id/flipCamera"
style="@android:style/Widget.Material.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|left"
android:padding="20dp"
android:clickable="true"
android:tint="@color/colorText"
android:backgroundTint="@color/colorText"
android:src="@drawable/ic_outline_camera_front_24px" />

<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/openGallery"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="center|right"
android:padding="20dp"
android:src="@drawable/fox"
android:clickable="true"
app:civ_border_color="#FF000000"
app:civ_border_width="2dp" />

</android.support.design.widget.CoordinatorLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center|top"
android:padding="10dp"
android:text="Pete is king!"
android:layout_gravity="center"
android:textColor="@color/colorText"
android:textSize="16sp" />

<ImageButton
android:id="@+id/info"
style="@android:style/Widget.Material.Button.Borderless"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|end"
android:layout_weight="1"
android:padding="20dp"
android:clickable="true"
android:backgroundTint="@color/colorAccent"
android:tint="@color/colorAccent"
android:src="@drawable/ic_shutterowl_24dp" />

</LinearLayout>
</LinearLayout>


And here is my viewpager:



<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<owlapps.shutterowl.AutoFitTextureView
android:id="@+id/texture"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_toEndOf="@+id/control"
xmlns:android="http://schemas.android.com/apk/res/android" />
</android.support.v4.view.ViewPager>


They are all showed together in a SlideUpPanelLayout like so:



<com.sothree.slidinguppanel.SlidingUpPanelLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
xmlns:sothree="http://schemas.android.com/apk/res-auto"
sothree:layout_constraintHeight_max="80dp"
sothree:umanoPanelHeight="120dp"
sothree:umanoShadowHeight="0dp"
sothree:umanoOverlay="true">

<include layout="@layout/camera_content"/>

<include layout="@layout/control_content"/>


</com.sothree.slidinguppanel.SlidingUpPanelLayout>


I had an idea to solve this with a interface that could trigger functions from the MainFragment that loads the camera and content layouts, here is what i tried:



In a click event from the mainfragment: Tab1Fragment.take.visible(true);



My interface looks like this:



public interface CameraControlListener {
void visible(boolean status);
}


And is implemented in the Tab1Fragment that holds the camera view:



@Override
public void visible(boolean status) {
if(status){
takePicture();
}
}


So how can I get all these to speak with eachother?
As i move between fragments i want the controls to change that are inside another fragment and also trigger functions from the active tabfragment in the viewpager.










share|improve this question























  • The activity holding all these fragments should be coordinating the communication. The fragments should never directly communicate.

    – Greg Moens
    Nov 25 '18 at 14:47











  • Ok. I tried from the mainactivity to get hold of objects in the other fragment but did get a null pointer exception since the items are in different fragments.

    – Major Bronco
    Nov 25 '18 at 22:27











  • Did you go through FragmentManager and use findFragmentById() or findFragmentByTag()?

    – Greg Moens
    Nov 25 '18 at 23:43











  • Can I really use fragmentmanager since the XML in the layout is not a fragment or should I just change it to a fragment instead of linearlayout

    – Major Bronco
    Nov 27 '18 at 16:03











  • You can use FragmentManager to get a hold of a fragment if the fragment was added with an ID or tag. If you want a change to the active fragment in a view pager to trigger other behavior, you probably want to attach an OnPageChangeListener to the pager.

    – Greg Moens
    Nov 27 '18 at 20:00














0












0








0








I don't really know how to ask this question but I will start off with the idea here.



So I have a MainFragment that contains a SlidingUpPanelLayout that includes a viewpager and a layout that hold the controls for the application.



And what I want to do is when I change between fragments in the tablayout I want to change the layout of that holds the controls, I also want to trigger functions from the fragment with the controls in on my different fragments in the viewpager.



But since they are in different fragments I don't know how to get the control layouts and buttons to change and get a hold of them.



So here is first an image of the layout:
https://imgur.com/a/SgdI21L



And here is how my following XML looks like:
XML for the Control Content:



<LinearLayout android:id="@+id/control"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#000"
android:clickable="false"
android:gravity="center|top"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@color/controlBackground"
app:tabGravity="fill"
app:tabIndicatorColor="@color/colorText"
app:tabMode="scrollable"
app:tabSelectedTextColor="@color/colorAccent"
app:tabTextColor="@color/colorText">
</android.support.design.widget.TabLayout>

<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<android.support.design.widget.FloatingActionButton
android:id="@+id/takePicture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|center_vertical"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:backgroundTint="@color/colorText"
android:clickable="true" />

<ImageButton
android:id="@+id/flipCamera"
style="@android:style/Widget.Material.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|left"
android:padding="20dp"
android:clickable="true"
android:tint="@color/colorText"
android:backgroundTint="@color/colorText"
android:src="@drawable/ic_outline_camera_front_24px" />

<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/openGallery"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="center|right"
android:padding="20dp"
android:src="@drawable/fox"
android:clickable="true"
app:civ_border_color="#FF000000"
app:civ_border_width="2dp" />

</android.support.design.widget.CoordinatorLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center|top"
android:padding="10dp"
android:text="Pete is king!"
android:layout_gravity="center"
android:textColor="@color/colorText"
android:textSize="16sp" />

<ImageButton
android:id="@+id/info"
style="@android:style/Widget.Material.Button.Borderless"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|end"
android:layout_weight="1"
android:padding="20dp"
android:clickable="true"
android:backgroundTint="@color/colorAccent"
android:tint="@color/colorAccent"
android:src="@drawable/ic_shutterowl_24dp" />

</LinearLayout>
</LinearLayout>


And here is my viewpager:



<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<owlapps.shutterowl.AutoFitTextureView
android:id="@+id/texture"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_toEndOf="@+id/control"
xmlns:android="http://schemas.android.com/apk/res/android" />
</android.support.v4.view.ViewPager>


They are all showed together in a SlideUpPanelLayout like so:



<com.sothree.slidinguppanel.SlidingUpPanelLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
xmlns:sothree="http://schemas.android.com/apk/res-auto"
sothree:layout_constraintHeight_max="80dp"
sothree:umanoPanelHeight="120dp"
sothree:umanoShadowHeight="0dp"
sothree:umanoOverlay="true">

<include layout="@layout/camera_content"/>

<include layout="@layout/control_content"/>


</com.sothree.slidinguppanel.SlidingUpPanelLayout>


I had an idea to solve this with a interface that could trigger functions from the MainFragment that loads the camera and content layouts, here is what i tried:



In a click event from the mainfragment: Tab1Fragment.take.visible(true);



My interface looks like this:



public interface CameraControlListener {
void visible(boolean status);
}


And is implemented in the Tab1Fragment that holds the camera view:



@Override
public void visible(boolean status) {
if(status){
takePicture();
}
}


So how can I get all these to speak with eachother?
As i move between fragments i want the controls to change that are inside another fragment and also trigger functions from the active tabfragment in the viewpager.










share|improve this question














I don't really know how to ask this question but I will start off with the idea here.



So I have a MainFragment that contains a SlidingUpPanelLayout that includes a viewpager and a layout that hold the controls for the application.



And what I want to do is when I change between fragments in the tablayout I want to change the layout of that holds the controls, I also want to trigger functions from the fragment with the controls in on my different fragments in the viewpager.



But since they are in different fragments I don't know how to get the control layouts and buttons to change and get a hold of them.



So here is first an image of the layout:
https://imgur.com/a/SgdI21L



And here is how my following XML looks like:
XML for the Control Content:



<LinearLayout android:id="@+id/control"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#000"
android:clickable="false"
android:gravity="center|top"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@color/controlBackground"
app:tabGravity="fill"
app:tabIndicatorColor="@color/colorText"
app:tabMode="scrollable"
app:tabSelectedTextColor="@color/colorAccent"
app:tabTextColor="@color/colorText">
</android.support.design.widget.TabLayout>

<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<android.support.design.widget.FloatingActionButton
android:id="@+id/takePicture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|center_vertical"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:backgroundTint="@color/colorText"
android:clickable="true" />

<ImageButton
android:id="@+id/flipCamera"
style="@android:style/Widget.Material.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|left"
android:padding="20dp"
android:clickable="true"
android:tint="@color/colorText"
android:backgroundTint="@color/colorText"
android:src="@drawable/ic_outline_camera_front_24px" />

<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/openGallery"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="center|right"
android:padding="20dp"
android:src="@drawable/fox"
android:clickable="true"
app:civ_border_color="#FF000000"
app:civ_border_width="2dp" />

</android.support.design.widget.CoordinatorLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center|top"
android:padding="10dp"
android:text="Pete is king!"
android:layout_gravity="center"
android:textColor="@color/colorText"
android:textSize="16sp" />

<ImageButton
android:id="@+id/info"
style="@android:style/Widget.Material.Button.Borderless"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|end"
android:layout_weight="1"
android:padding="20dp"
android:clickable="true"
android:backgroundTint="@color/colorAccent"
android:tint="@color/colorAccent"
android:src="@drawable/ic_shutterowl_24dp" />

</LinearLayout>
</LinearLayout>


And here is my viewpager:



<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<owlapps.shutterowl.AutoFitTextureView
android:id="@+id/texture"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_toEndOf="@+id/control"
xmlns:android="http://schemas.android.com/apk/res/android" />
</android.support.v4.view.ViewPager>


They are all showed together in a SlideUpPanelLayout like so:



<com.sothree.slidinguppanel.SlidingUpPanelLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
xmlns:sothree="http://schemas.android.com/apk/res-auto"
sothree:layout_constraintHeight_max="80dp"
sothree:umanoPanelHeight="120dp"
sothree:umanoShadowHeight="0dp"
sothree:umanoOverlay="true">

<include layout="@layout/camera_content"/>

<include layout="@layout/control_content"/>


</com.sothree.slidinguppanel.SlidingUpPanelLayout>


I had an idea to solve this with a interface that could trigger functions from the MainFragment that loads the camera and content layouts, here is what i tried:



In a click event from the mainfragment: Tab1Fragment.take.visible(true);



My interface looks like this:



public interface CameraControlListener {
void visible(boolean status);
}


And is implemented in the Tab1Fragment that holds the camera view:



@Override
public void visible(boolean status) {
if(status){
takePicture();
}
}


So how can I get all these to speak with eachother?
As i move between fragments i want the controls to change that are inside another fragment and also trigger functions from the active tabfragment in the viewpager.







android android-layout android-fragments






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 25 '18 at 13:13









Major BroncoMajor Bronco

13




13













  • The activity holding all these fragments should be coordinating the communication. The fragments should never directly communicate.

    – Greg Moens
    Nov 25 '18 at 14:47











  • Ok. I tried from the mainactivity to get hold of objects in the other fragment but did get a null pointer exception since the items are in different fragments.

    – Major Bronco
    Nov 25 '18 at 22:27











  • Did you go through FragmentManager and use findFragmentById() or findFragmentByTag()?

    – Greg Moens
    Nov 25 '18 at 23:43











  • Can I really use fragmentmanager since the XML in the layout is not a fragment or should I just change it to a fragment instead of linearlayout

    – Major Bronco
    Nov 27 '18 at 16:03











  • You can use FragmentManager to get a hold of a fragment if the fragment was added with an ID or tag. If you want a change to the active fragment in a view pager to trigger other behavior, you probably want to attach an OnPageChangeListener to the pager.

    – Greg Moens
    Nov 27 '18 at 20:00



















  • The activity holding all these fragments should be coordinating the communication. The fragments should never directly communicate.

    – Greg Moens
    Nov 25 '18 at 14:47











  • Ok. I tried from the mainactivity to get hold of objects in the other fragment but did get a null pointer exception since the items are in different fragments.

    – Major Bronco
    Nov 25 '18 at 22:27











  • Did you go through FragmentManager and use findFragmentById() or findFragmentByTag()?

    – Greg Moens
    Nov 25 '18 at 23:43











  • Can I really use fragmentmanager since the XML in the layout is not a fragment or should I just change it to a fragment instead of linearlayout

    – Major Bronco
    Nov 27 '18 at 16:03











  • You can use FragmentManager to get a hold of a fragment if the fragment was added with an ID or tag. If you want a change to the active fragment in a view pager to trigger other behavior, you probably want to attach an OnPageChangeListener to the pager.

    – Greg Moens
    Nov 27 '18 at 20:00

















The activity holding all these fragments should be coordinating the communication. The fragments should never directly communicate.

– Greg Moens
Nov 25 '18 at 14:47





The activity holding all these fragments should be coordinating the communication. The fragments should never directly communicate.

– Greg Moens
Nov 25 '18 at 14:47













Ok. I tried from the mainactivity to get hold of objects in the other fragment but did get a null pointer exception since the items are in different fragments.

– Major Bronco
Nov 25 '18 at 22:27





Ok. I tried from the mainactivity to get hold of objects in the other fragment but did get a null pointer exception since the items are in different fragments.

– Major Bronco
Nov 25 '18 at 22:27













Did you go through FragmentManager and use findFragmentById() or findFragmentByTag()?

– Greg Moens
Nov 25 '18 at 23:43





Did you go through FragmentManager and use findFragmentById() or findFragmentByTag()?

– Greg Moens
Nov 25 '18 at 23:43













Can I really use fragmentmanager since the XML in the layout is not a fragment or should I just change it to a fragment instead of linearlayout

– Major Bronco
Nov 27 '18 at 16:03





Can I really use fragmentmanager since the XML in the layout is not a fragment or should I just change it to a fragment instead of linearlayout

– Major Bronco
Nov 27 '18 at 16:03













You can use FragmentManager to get a hold of a fragment if the fragment was added with an ID or tag. If you want a change to the active fragment in a view pager to trigger other behavior, you probably want to attach an OnPageChangeListener to the pager.

– Greg Moens
Nov 27 '18 at 20:00





You can use FragmentManager to get a hold of a fragment if the fragment was added with an ID or tag. If you want a change to the active fragment in a view pager to trigger other behavior, you probably want to attach an OnPageChangeListener to the pager.

– Greg Moens
Nov 27 '18 at 20:00












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53467818%2fcommunicate-between-fragments-and-layouts%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53467818%2fcommunicate-between-fragments-and-layouts%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

TypeError: fit_transform() missing 1 required positional argument: 'X'