Update Facebook within Pageview with Tab

Asked

Viewed 116 times

0

Galley,

See if you can help me, I’ve had this problem for two days and I can’t fix it.

My app got Pagaview, Tablayou, and 3 Fragment Ok? As picture below: inserir a descrição da imagem aqui

In my third tab I have the following Fragment code:

android.support.v4.app.Fragment fragment3  = new SearchActivity(); // replace your custom fragment class
String className = fragment3.getClass().getName();
Bundle bundle = new Bundle();
android.support.v4.app.FragmentTransaction fragmentTransaction = getActivity().getSupportFragmentManager().beginTransaction();
bundle.putString(KEY_QUERY, suggestion); // use as per your need
fragment3.setArguments(bundle);
fragmentTransaction.addToBackStack(className);
fragmentTransaction.add(R.id.container,fragment3);
fragmentTransaction.commit();

That code calls the SAME Fragment passing as parameter the text I clicked, soon after that Fragment is recreated but it is over the pageview, hiding all the other Factions.

I’ve tried to use it that way, but no effect.

fragmentTransaction.addToBackStack(className);

I am using a Fragment Container as below:

public class ContainerFragment extends Fragment {

    private static TabLayoutSetupCallback mToolbarSetupCallback;
    private List<String> mTabNamesList;

    static ViewPager viewPager;

    public ContainerFragment() {
        // Required empty public constructor
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);

        if (context instanceof MainActivity) {
            mToolbarSetupCallback = (TabLayoutSetupCallback) context;
        } else {
            throw new ClassCastException(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);
    }
}

Summarizing: I need to recreate the Fragment by passing as parameter the text I clicked and this Fragment stay inside the Pageview working correctly the TAB.

If need be I can make video showing the problem.

1 answer

1

uses replace add and remove the current

fragmentTransaction.replace(R.id.container,fragment3);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.