Refresh fragment within Pageview with Tab

0

Galera,

See if you can help me, I've had this problem for 2 days and I can not resolve it.

My app has PagaView, TabLayou, and 3 Fragment Ok? As the image below:

OnmythirdtabIhavethefollowingFragmentcode:

android.support.v4.app.Fragmentfragment3=newSearchActivity();//replaceyourcustomfragmentclassStringclassName=fragment3.getClass().getName();Bundlebundle=newBundle();android.support.v4.app.FragmentTransactionfragmentTransaction=getActivity().getSupportFragmentManager().beginTransaction();bundle.putString(KEY_QUERY,suggestion);//useasperyourneedfragment3.setArguments(bundle);fragmentTransaction.addToBackStack(className);fragmentTransaction.add(R.id.container,fragment3);fragmentTransaction.commit();

ThiscodecallstheMESMAfragmentpassingasaparameterthetextthatIclicked,soonafterthatthefragmentisre-created,butitisoverpageview,hidingallotherfragments.

I'vetriedtouseitthisway,butnoeffect.

fragmentTransaction.addToBackStack(className);

I'musingaFragmentConteinerasbelow:

publicclassContainerFragmentextendsFragment{privatestaticTabLayoutSetupCallbackmToolbarSetupCallback;privateList<String>mTabNamesList;staticViewPagerviewPager;publicContainerFragment(){//Requiredemptypublicconstructor}@OverridepublicvoidonAttach(Contextcontext){super.onAttach(context);if(contextinstanceofMainActivity){mToolbarSetupCallback=(TabLayoutSetupCallback)context;}else{thrownewClassCastException(context.toString()+" must implement TabLayoutSetupCallback");
        }
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        android.support.v4.app.Fragment fragment = null;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        android.support.v4.app.Fragment fragment = null;
        fragment = new Galeria();
        android.support.v4.app.Fragment fragment2 = new PageFragment();
        //android.support.v4.app.Fragment fragment3 = new MainActivityGif();

        final String query = "BOm DIA";//textView.getText().toString().trim();

        android.support.v4.app.Fragment fragment3  = new SearchActivity(); // replace your custom fragment class
        Bundle bundle = new Bundle();

        bundle.putString(query, query); // use as per your need
        fragment3.setArguments(bundle);


        View view = inflater.inflate(R.layout.fragment_container, container, false);
        viewPager = (ViewPager) view.findViewById(R.id.viewPager);

        ContainerFragment.ItemsPagerAdapter adapter = new ContainerFragment.ItemsPagerAdapter(getChildFragmentManager());
        adapter.addFrag(fragment, "ONE");
        adapter.addFrag(fragment2, "TWO");
        adapter.addFrag(fragment3, "THREE");
        viewPager.setOffscreenPageLimit(9);
        viewPager.setAdapter(adapter);
        mToolbarSetupCallback.setupTabLayout(viewPager);

        return view;
    }


    public static class ItemsPagerAdapter extends FragmentStatePagerAdapter {

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

        public ItemsPagerAdapter(FragmentManager fm) {
            super(fm);

            //mTabs = tabNames;
        }

        @Override
        public Fragment getItem(int position) {
           // return PageFragment.newInstance();
            //return mFragmentList.newInstance(data.get(position),position);
            return mFragmentList.get(position);
        }

        @Override
        public int getItemPosition(Object object) {
            return POSITION_NONE;
        }

        @Override
        public int getCount() {
            return mFragmentList.size();
        }

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

        public void addFrag(Fragment fragment, String title) {
            mFragmentList.add(fragment);
            mFragmentTitleList.add(title);
        }


    }

    public interface TabLayoutSetupCallback {
        void setupTabLayout(ViewPager viewPager);
    }
}

In short, I need to recreate the Fragment by passing the text I clicked as a parameter and this fragment is inside the Pageview working correctly the TAB.

If necessary, I can make video showing the problem.

    
asked by anonymous 29.08.2018 / 16:36

1 answer

1

use replace adds and removes the current

fragmentTransaction.replace(R.id.container,fragment3);
    
10.09.2018 / 20:35