简体   繁体   中英

How to open a fragment on clicking to RecyclerView item which is implemented in another fragment which is again can be swiped by using ViewPager?

I have a ViewPager consisting of 5 fragments. Have a RecyclerView in the first fragment showing list of dishes items. I have implemented click listeners on the RecyclerView items, but now I want to open a fragment that would show more information about the dish clicked and this fragment should replace the fragment that is holding RecyclerView and is not one of the 5 fragment of ViewPager.

How can I call the Dish information fragment with the click listener inside of RecyclerView item, inside of a fragment controlled by ViewPager so as to replace the former ViewPager fragment with the Dish Information Fragment?

You need to make a new fragment ie dish detail fragment. Now on recycler view list item click replace your existing fragment with itemDetail fragment. Example:- I am supposing that your container view is "R.id.fragmentContainer" and in this container your are loading the fragment.

Now just call this code on recyclerView item click

    ItemDetailFragment itemDetailFragment=new ItemDetailFragment();

    FragmentTransaction transaction = 
      getFragmentManager().beginTransaction();

    transaction.setCustomAnimations(animSlideIn, animSlideOut, animSlideIn, animSlideOut);
    transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN).replace(R.id.fragmentContainer, itemDetailFragment)
            .commitAllowingStateLoss();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM