So if I have three Fragments A,B, and C.
So when I launch Fragment B I want viewpager to let me swipe from LEFT to RIGHT and it should take me back to Fragment A, but viewpager, by default lets me swipe from RIGHT to LEFT to go to Fragment A.
So basically I want viewpager to let me swipe from LEFT to RIGHT and not from RIGHT to LEFT.
Also I tried:
viewpager.setRotationY=180
That does let me do what I want but all the contents in my Fragments get flipped upside down.
The adapter I am using:
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import org.jetbrains.annotations.NotNull;
public class Adapter extends FragmentPagerAdapter {
public Adapter(FragmentManager fragmentManager){
super(fragmentManager);
}
#NonNull
#NotNull
#Override
public Fragment getItem(int position) {
if(position==0){
return new SettingsFragment();
}
if(position==1){
return new BlankFragment();
}
if(position==2){
return new VersionFragment();
}
return null;
}
#Override
public int getCount() {
return 3;
}
}
The activity where I use the adapter:
public class SettingsActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
Fragment fr=new Fragment();
getSupportFragmentManager().beginTransaction().addToBackStack(null).add(fr,"settings_fragment").commit();
runOnUiThread(new Runnable() {
#Override
public void run() {
ViewPager viewPager=findViewById(R.id.ViewPager);
viewPager.setCurrentItem(1);
viewPager.setAdapter(new Adapter(getSupportFragmentManager()));
viewPager.setOffscreenPageLimit(1);
}
});
}
}
I think your code is misleading you, because you using viewPager.setCurrentItem(1); before setAdapter(...) which you ViewPager will not go to item 1 as you expected.
So, try put that viewPager.setCurrentItem(1); after setAdapter(...)
Related
This question already has answers here:
How do disable paging by swiping with finger in ViewPager but still be able to swipe programmatically?
(27 answers)
Closed 4 years ago.
I have a working code. I have a TabLayout menu and two items in it. This code works. But when I scroll the screen to the right or left, the other fragment opens. I dont want this. Click on the tab menu and I want the fragment to open. For example, I want A fragment to be opened when A fragment is pushed.
MyFragmentAdapter
public class MyFragmentAdapter extends FragmentPagerAdapter {
int tabCount;
public MyFragmentAdapter(FragmentManager fm, int numberOfTabs) {
super(fm);
this.tabCount = numberOfTabs;
}
#Override
public Fragment getItem(int position) {
switch (position) {
case 0:
WebFragment tab1 = new AFragment();
return tab1;
case 1:
PromotionFragment tab2 = new BFragment();
return tab2;
default:
return null;
}
}
#Override
public int getCount() {
return tabCount;
}
}
MyActivity
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
TabLayout tabLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/** TabLayout and Fragments */
tabLayout = findViewById(R.id.tab_layout);
tabLayout.addTab(tabLayout.newTab().setText("A"));
tabLayout.addTab(tabLayout.newTab().setText("B"));
viewPager = findViewById(R.id.pager);
final PagerAdapter adapter = new MyFragmentAdapter(getSupportFragmentManager(), tabLayout.getTabCount());
viewPager.setAdapter(adapter);
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
#Override
public void onTabSelected(TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
}
#Override
public void onTabUnselected(TabLayout.Tab tab) {
}
#Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
}
}
More simple solution by custom ViewPager to a non swipe ViewPager.
Add this class
import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.animation.DecelerateInterpolator;
import android.widget.Scroller;
import java.lang.reflect.Field;
public class NonSwipeableViewPager extends ViewPager {
public NonSwipeableViewPager(Context context) {
super(context);
}
public NonSwipeableViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
#Override
public boolean onInterceptTouchEvent(MotionEvent arg0) {
// Never allow swiping to switch between pages
return false;
}
#Override
public boolean onTouchEvent(MotionEvent event) {
// Never allow swiping to switch between pages
return false;
}
}
in XML layout instead using ViewPager, replace by NonSwipeableViewPager so you can achieve "just click to tab to go to fragment"
i followed this article http://www.truiton.com/2015/06/android-tabs-example-fragments-viewpager/ to implement swipe view and it work nice. So now i want to add button on Tab1 and when clicked has to send data to Tab2.
I know there is the issue of using interface but honestly i don't know how to add it on these codes and work provide am completely new to the android.
so far i have tried my best on these links Communication between SlidingTabLayout tabs, How to pass data from one swipe tab to another? and How can I communicate/pass data through different Fragments with Swipe Tab? but i fail.
Any one help please to make it work on every stage , i mean from Tab1 ->Mainactivity->Tab2
thanks alot
Here are the codes after i edit the question
Fragment1
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class TabFragment1 extends Fragment implements AdapterView.OnItemSelectedListener{
Button send;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v= inflater.inflate(R.layout.tab_fragment_1, container, false);
send=(Button)v.findViewById(R.id.send);
send.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// value to be sent to the TabFragment2 on button click
String value=" My Data";
}
});
return v;
}
}
Fragment2
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class TabFragment2 extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.tab_fragment_2, container, false);
//Display value from TabFragment1
textview.setText(value);
}
}
Interface class
public Interface FragmentCommunication
{
public void printMessage(String message);
}
MainActivity
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends AppCompatActivity implements FragmentCommunication{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
tabLayout.addTab(tabLayout.newTab().setText("Tab 1"));
tabLayout.addTab(tabLayout.newTab().setText("Tab 2"));
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
final PagerAdapter adapter = new PagerAdapter
(getSupportFragmentManager(), tabLayout.getTabCount());
viewPager.setAdapter(adapter);
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
#Override
public void onTabSelected(TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
}
#Override
public void onTabUnselected(TabLayout.Tab tab) {
}
#Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
}
public void printMessage(String message)
{
Toast.makeText(MainActivity.this,message,Toast.LENGTH_LONG).show();
}
}
Adapter Class
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
public class PagerAdapter extends FragmentStatePagerAdapter {
int mNumOfTabs;
public PagerAdapter(FragmentManager fm, int NumOfTabs) {
super(fm);
this.mNumOfTabs = NumOfTabs;
}
#Override
public Fragment getItem(int position) {
switch (position) {
case 0:
TabFragment1 tab1 = new TabFragment1();
return tab1;
case 1:
TabFragment2 tab2 = new TabFragment2();
return tab2;
default:
return null;
}
}
#Override
public int getCount() {
return mNumOfTabs;
}
}
so after posting more code I'm answering:
Implement some FragmentCommunication for both your Fragments:
//public class TabFragment1 extends Fragment implements FragmentCommunication{
public class TabFragment2 extends Fragment implements FragmentCommunication{
//public static final String TAG="TabFragment1";
public static final String TAG="TabFragment2";
...
#Override
public void onActivityCreated (Bundle savedInstanceState){
super.onActivityCreated(savedInstanceState);
if(getActivity() instanceOf MainActivity)
((MainActivity) getActivity()).registerFragmentCommunication(
TAG, this);
}
#Override
public void printMessage(String message){
Toast.makeText(getActivity(), TAG+" says: "+message,
Toast.LENGTH_SHORT).show();
}
}
note this line inside onActivityCreated:
((MainActivity) getActivity()).registerFragmentCommunication(TAG, this);
this means implemented FragmentCommunication, TAG will be unique key/name of Fragment and whole method is registration of your interface in Activity. so now you have to add registerFragmentCommunication method to your MainActivity and keep reference to passed interfaces, e.g. in HashMap:
HashMap<String, FragmentCommunication> fragmentCommunications =
new HashMap<String, FragmentCommunication>();
...
public void registerFragmentCommunication(String key, FragmentCommunication fc){
fragmentCommunications.put(key, fc);
}
so now you can access each FragmentCommunication of both fragments from your MainActivity, e.g by using method like this:
public void callFragmentCommunication(String key, String msg){
if(fragmentCommunications.get(key)!=null)
fragmentCommunications.get(key).printMessage();
}
callFragmentCommunication(TabFragment1.TAG, "hi!");
callFragmentCommunication(TabFragment2.TAG, "hi!");
method is public, so Fragments can call it simply like this:
//inside TabFragment1
if(isAdded() && getActivity()!=null &&
getActivity() instanceOf MainActivity &&
!getActivity().isFinishing())
((MainActivity) getActivity()).callFragmentCommunication(
TabFragment2.TAG, "hi!");
this will show Toast with text: "TabFragment2 says: hi!", which was called inside TabFragment1. now you may pass another kind of data as well :)
there is much more methods like communicating through FragmentStatePagerAdapter like here, passing Bundle arguments where fragments are initialized, additional feedback interfaces (e.g. returning true/false when message was passed) etc. Above is just very simplified way, good luck with improving it! :)
My application is working fine when I use getChildFragmentManager() but unfortunately, it will only work with API 17 and above. Now when I switch it over to getFragmentManager(), everything works fine except for one thing. Whenever I load my tablayout in horizontal view, both pages are empty and swiping is sluggish. Vertically it is fine and they won't be empty if I first load them vertically and then switch to horizontally, because I'm using a saved instance. I have no idea what is causing this. All I know is that as soon as I switch the code above around, it happens. Let me know what is required to find the issue and I will gladly post it. I am using the support-v13 library's FragmentPagerAdapter. I am doing this so I don't have to use support-v4's way of creating fragments. I do import the ViewPager from v4 in my tablayout fragment.
Edit:
Okay when the tablayout is created for the first time, it works fine. When called again it will be blank and sluggish. It had nothing to do with orientation.
Edit:
Tablayout code Keep in mind that this code is functional. But when I change getChildFragmentManager() to getFragmentManager() it gets sluggish and only works on first oncreate:
import android.app.Fragment;
import android.app.FragmentManager;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v13.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class TabFragment extends Fragment {
public static TabLayout tabLayout;
public static ViewPager viewPager;
public static int int_items = 2;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View x = inflater.inflate(R.layout.tab_layout, null);
tabLayout = (TabLayout) x.findViewById(R.id.tabs);
viewPager = (ViewPager) x.findViewById(R.id.viewpager);
viewPager.setAdapter(new MyAdapter(getChildFragmentManager()));
tabLayout.post(new Runnable() {
#Override
public void run() {
tabLayout.setupWithViewPager(viewPager);
}
});
return x;
}
class MyAdapter extends FragmentPagerAdapter {
public MyAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
switch (position) {
case 0:
return new FragmentOne();
case 1:
return new FragmentTwo();
}
return null;
}
#Override
public int getCount() {
return int_items;
}
#Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 0:
return "TAB1";
case 1:
return "TAB2";
}
return null;
}
}
}
i'm working on application in eclipse that have 5 tab and i have spent much time for that but now i have a big problem :
when one of tabs is activated the next tab and prev tab is loading too
and onCreated() method is called but i don't need that i need just
calling onCreated() method when switching to tabs
This is my project files
mainActivity.java
package info.androidhive.tabsswipe;
import info.androidhive.tabsswipe.adapter.TabsPagerAdapter;
import ir.zinoo.mankan.R;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.FragmentTransaction;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.content.SharedPreferences;
public class MainActivity extends FragmentActivity implements ActionBar.TabListener {
private ViewPager viewPager;
private TabsPagerAdapter mAdapter;
private ActionBar actionBar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initilization
viewPager = (ViewPager) findViewById(R.id.pager);
actionBar = getActionBar();
mAdapter = new TabsPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(mAdapter);
actionBar.setHomeButtonEnabled(false);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
//Adding Tabs
for (String tab_name : tabs) {
actionBar.addTab(actionBar.newTab().setTabListener(this));
}
actionBar.setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#333333")));
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#333333")));
viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
#Override
public void onPageSelected(int position) {
// on changing the page
// make respected tab selected
actionBar.setSelectedNavigationItem(position);
}
#Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
}
#Override
public void onPageScrollStateChanged(int arg0) {
}
});
}
#Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
}
#Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
// on tab selected
// show respected fragment view
viewPager.setCurrentItem(tab.getPosition());
}
#Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
}
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
tabPagerAdapter.java class
package info.androidhive.tabsswipe.adapter;
import info.androidhive.tabsswipe.BmiFragment;
import info.androidhive.tabsswipe.CaloriFragment;
import info.androidhive.tabsswipe.FatFragment;
import info.androidhive.tabsswipe.KamarFragment;
import info.androidhive.tabsswipe.OstokhanFragment;
import info.androidhive.tabsswipe.OtherFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
public class TabsPagerAdapter extends FragmentPagerAdapter {
public TabsPagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int index) {
switch (index) {
case 0:
// Top Rated fragment activity
return new BmiFragment();
case 1:
// Games fragment activity
return new CaloriFragment();
case 2:
// Movies fragment activity
return new KamarFragment();
case 3:
// Movies fragment activity
return new OstokhanFragment();
case 4:
// Movies fragment activity
return new FatFragment();
case 5:
// Movies fragment activity
return new OtherFragment();
}
return null;
}
#Override
public int getCount() {
//get item count - equal to number of tabs
return 6;
}
}
Now My question is How to avoid calling on created method of other tabs when in switch to special tab?
From Android Documentation about FragmentPagerAdapter :
This version of the pager is best for use when there are a handful of typically more static fragments to be paged through, such as a set of tabs. The fragment of each page the user visits will be kept in memory, though its view hierarchy may be destroyed when not visible. This can result in using a significant amount of memory since fragment instances can hold on to an arbitrary amount of state. For larger sets of pages, consider FragmentStatePagerAdapter
FragmentStatePagerAdapter :
This version of the pager is more useful when there are a large number
of pages, working more like a list view. When pages are not visible to
the user, their entire fragment may be destroyed, only keeping the
saved state of that fragment. This allows the pager to hold on to much
less memory associated with each visited page as compared to
FragmentPagerAdapter at the cost of potentially more overhead when
switching between pages.
So, as you are using FragmentPagerAdapter, FrgmentManager will add all your fragment in memory while user is using app. Furthermore, when user switches to any page, FragmentManager loads previous and next page and it will call onCreate() of your tabs.
As you have now 6 tabs, may be you want to add more tabs, FragmentStatePagerAdapter is more suitable.
For checking exactly which fragment is visible to user, you can do something like this :
public class TabsPagerAdapter extends FragmentPagerAdapter {
/* declare fragment objects here globally */
BmiFragment mBmi = new BmiFragment();
CaloriFragment mCalori = new CaloriFragment();
KamarFragment mKamar = new KamarFragment();
public TabsPagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int index) {
switch (index) {
case 0:
// Top Rated fragment activity
mBmi.setUserVisibleHint(false);
return mBmi;
case 1:
// Games fragment activity
mCalori.setUserVisibleHint(false);
return mCalori;
case 2:
// Movies fragment activity
mKamar.setUserVisibleHint(false);
return mKamar;
/* like this for all case*/
}
return null;
}
}
Set onPageChangeListener to ViewPager from your Activity :
mPager.setOnPageChangeListener(new OnPageChangeListener() {
#Override
public void onPageSelected(int position) {
// position tab is visible to user
switch(position) {
case 0 :
mBmi.setUserVisibleHint(true);
break;
/* like this for all case */
}
}
});
Override setUserVisibleHint() method in all fragments :
public class <Your_Fragment> extends Fragment {
#Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if (isVisibleToUser) {
// do something, your fragment is visible
} else {
// your fragment is loaded, but not visible to user currently
}
}
}
This is killing me. I have one DemoFragment which has 3 instances created. Within these instances different data is loaded into the fragments. What I want to be able to do is have a button (within the fragment) that forces all of the Fragments to refresh or reload. This is necessary as the button also commits new data that needs to be pulled newly for every fragment.
I've search plenty of solutions, but can't get to the bottom of it. Currently I have a an activity, fragment and adapter. Below is the abridged code (as expected this loads 3 pages):
Activity (RoutineDetailsActivity.java)
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
public class RoutineDetailsActivity extends FragmentActivity {
ViewPager mViewPager;
Button mLogout;
CustomPagerAdapter mSectionsPagerAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_routine_details);
mSectionsPagerAdapter = new CustomPagerAdapter(getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
}
}
Adapter (CustomPagerAdapter.java)
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import java.util.Locale;
public class CustomPagerAdapter extends FragmentStatePagerAdapter {
public CustomPagerAdapter (FragmentManager fm) {
super(fm);
}
#Override
public int getCount() {
return 3;
}
#Override
public Fragment getItem(int position) {
return DemoFragment.newInstance(position);
}
#Override
public int getItemPosition(Object object) {
return POSITION_NONE;
}
}
}
Fragment (DemoFragment.java)
public class DemoFragment extends Fragment {
int mNum;
static DemoFragment newInstance(int num) {
DemoFragment f = new DemoFragment();
Bundle args = new Bundle();
args.putInt("num", num);
f.setArguments(args);
return f;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mNum = getArguments() != null ? getArguments().getInt("num") : 1;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_routine_details, container, false);
}
#Override
public void onResume() {
// CODE CLIPPED, do loads of sh*t
Button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// New data uploaded to server
// What code to force reload the fragments?
}
});
}
So within this code, more specifically, within the button click, what do I need to do to force the all Fragments to reload and retrieve the latest data.
I've sen answers around this, but I'm sure how to relate it to here.
Thanks.
If you a willing to add a small library called EventBus: https://github.com/greenrobot/EventBus
You can do like this:
public class AnyFragment extends Fragment {
#Override
public void onAttach(final Activity activity) {
super.onAttach(activity);
EventBus.getDefault().register(this);
}
#Override
public void onDetach() {
EventBus.getDefault().unregister(this);
super.onDetach();
}
public void onEventMainThread(UpdateUIEvent ev) {
// perform refresh
}
}
UpdateUIEvent is just a simple empty object in my case but could contain arbitrary data as well:
public class UpdateUIEvent {}
With this in place you can refresh AnyFragment from anywhere in your code by doing:
EventBus.getDefault().post(new UpdateUIEvent());
I want to stress that you can do this Anywhere, but in you case, the above line would be the only thing you would have to do in click of your button. Then all fragments listening, as shown with AnyFragment, will receive the event :)
Implement an interface in your fragment say IRefresher. Keep track of references of the 3 fragments in your activity. When button is clicked call the interface method say refreshMe() which would work as a listener/callback in the fragments and in that method refresh your fragment.
I have done it in one of my project and it works flawlessly
I am not sure whether I have understood your problem or not. From your button trigger you can call the parent activity which one is holding all the fragments. Create a method in the parent activity. Inside the method register listener (Call Interface method) which update the fragments lists. Call the parent method from fragment(s) when you need it.