Q: how can i change text and control visiblity of activity from viewpager's fragment I have a viewpager with 5 fragment that handle the fragment view by TabLayout. all of them are in activity and i want when the second tablayout selected the activity's textview's text changes and also two of my control's Visibility should be Gone.

this is what i did for viewpager:
   protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_page);
         tf = Typeface.createFromAsset(getAssets(), "IRANSans_Bold.ttf");
        context=this;
        /*if(UIHelper.check_screenSize(this, Configuration.SCREENLAYOUT_SIZE_SMALL))
        {
            FloatingActionButton fab=(FloatingActionButton)UIHelper.getInstance(this,R.id.fav_GetAddress, Tags.fab);

            fab.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        }*/
        Display display=getWindowManager().getDefaultDisplay();
        int height=display.getHeight();

        tabCustomization();
        /*changeTabsFont();*/
        setupTabIcons();

        tabLayout.getTabAt(0).getIcon().setColorFilter(Color.parseColor("#f6fda6"), PorterDuff.Mode.SRC_IN);
        linearLayout=(LinearLayout)tabLayout.getTabAt(0).getCustomView();
        ImageView firstTab=(ImageView)linearLayout.getChildAt(0);
        firstTab.setColorFilter(Color.parseColor("#f6fda6"), PorterDuff.Mode.SRC_IN);
        fav_GetAddress();

    }

   /* @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Toast.makeText(this,"get Activity camera result",Toast.LENGTH_LONG).show();

    }*/

    private void tabCustomization() {
        viewPager = (CustomViewPager) findViewById(R.id.viewPager);
        viewPager.setPagingEnabled(false);

        setupViewPager(viewPager);
        tabLayout = (TabLayout) findViewById(R.id.tabs);

        tabLayout.setupWithViewPager(viewPager);
        ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());

        adapter.addFragment(new MenuFragment(), "Menu");

        adapter.addFragment(new AddressFragment(), "Fave Address");
        adapter.addFragment(new SearchFragment(), "Searching");
        adapter.addFragment(new IssueFragment(), "Another Info");
        adapter.addFragment(new ProfileFragment(), "Login");

        viewPager.setAdapter(adapter);
        viewPager.setOffscreenPageLimit(5);
        for (int i = 0; i < tabLayout.getTabCount(); i++) {
            TabLayout.Tab tab = tabLayout.getTabAt(i);


            tab.setCustomView(adapter.getTabView(tabLayout,i));

        }


        ViewGroup vg = (ViewGroup) tabLayout.getChildAt(0);
        int tabsCount = vg.getChildCount();
        Log.i("TabChild",String.valueOf(tabsCount));


// Iterate over all tabs and set the custom view

    }

    public void setupViewPager(ViewPager viewPager) {

    }
    private void setupTabIcons() {

        tabLayout.getTabAt(0).setIcon(tabIcons[0]);
        tabLayout.getTabAt(1).setIcon(tabIcons[1]);
        tabLayout.getTabAt(2).setIcon(tabIcons[2]);
        tabLayout.getTabAt(3).setIcon(tabIcons[3]);
        tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener(){


            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                /*tab.getIcon().setColorFilter(Color.parseColor("#a8a8a8"), PorterDuff.Mode.SRC_IN);*/



                linearLayout=(LinearLayout)tab.getCustomView();
                ImageView v=(ImageView)linearLayout.getChildAt(0);
                v.setColorFilter(Color.parseColor("#f6fda6"), PorterDuff.Mode.SRC_IN);
                TextView google_header_address=(TextView)findViewById(R.id.google_header_address);
                TextView select_address=(TextView)findViewById(R.id.select_address);
                ImageView fav_GetAddress=(ImageView)findViewById(R.id.fav_GetAddress);

                switch (tab.getPosition())
                {
                    case 0:
                        google_header_address.setText("where to get it?");
                        select_address.setText("Adding Fav Address");
                        fav_GetAddress.setVisibility(View.VISIBLE);
                        break;
                    case 1:
                    google_header_address.setText("");
                    select_address.setText("Select Address");
                    fav_GetAddress.setVisibility(View.GONE);
                        break;
                    case 2:
                        google_header_address.setText("");
                        select_address.setText("Searching Info");
                        fav_GetAddress.setVisibility(View.GONE);
                        break;
                    case 3:
                        google_header_address.setText("");
                        select_address.setText("AnotherText");
                        fav_GetAddress.setVisibility(View.GONE);
                        break;
                    case 4:
                        google_header_address.setText("");
                        select_address.setText("login");
                        fav_GetAddress.setVisibility(View.GONE);
                        break;

                }

            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

                 linearLayout=(LinearLayout)tab.getCustomView();
                ImageView v=(ImageView)linearLayout.getChildAt(0);
                v.setColorFilter(Color.parseColor("#ffffff"), PorterDuff.Mode.SRC_IN);
            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {
            }
        });


    }


    class ViewPagerAdapter extends FragmentPagerAdapter {

        private final List<Fragment> mFragmentList = new ArrayList<>();
        private final List<String> mFragmentTitleList = new ArrayList<>();

        public ViewPagerAdapter(FragmentManager manager) {
            super(manager);
        }


        @Override
        public Fragment getItem(int position) {
            return mFragmentList.get(position);
        }
        @Override
        public int getCount() {
            return mFragmentList.size();
        }

        public void addFragment(Fragment fragment, String title) {
            mFragmentList.add(fragment);
            mFragmentTitleList.add(title);
        }
        public View getCustomView(TabLayout tabLayout,int position){
            View view = LayoutInflater.from(getApplicationContext())
                    .inflate(R.layout.custom_tab, tabLayout, false);
            TextView textView= (TextView) view.findViewById(R.id.tabText);

            textView.setText(getPageTitle(position));
            textView.setTypeface(tf);

            ImageView imageView = (ImageView) view.findViewById(R.id.imageView);
            imageView.setImageResource(tabIcons[position]);

            return view;
        }
        public View getTabView(TabLayout tabLayout,int position) {
            // Given you have a custom layout in `res/layout/custom_tab.xml` with a TextView and ImageView

            View view = LayoutInflater.from(getApplicationContext())
                    .inflate(R.layout.custom_tab, tabLayout, false);
            TextView textView= (TextView) view.findViewById(R.id.tabText);

            textView.setText(getPageTitle(position));
            textView.setTypeface(tf);

            ImageView imageView = (ImageView) view.findViewById(R.id.imageView);
            imageView.setImageResource(tabIcons[position]);

            return view;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mFragmentTitleList.get(position);
        }


A: override setOnTabSelectedListener for your tablayout in  activity and update your activity text view .
Like
toolbarTabs.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
           if(tab.getPosition()==2){
       //update your textview of activity

  }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {
           if(tab.getPosition()==2){
        //update your textview of activity
            }
        });


A: create public method in Activity class.
public void update(String updateStr) {
// update here
}

And in onCreateView of fragment you can call 
String updateStr = "updateStr";
((AddYourActivityName) getActivity()).update(updateStr); 

