[英]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?
我有一個由5個片段組成的ViewPager。 在第一個片段中包含一個RecyclerView,以顯示餐具列表。 我已經在RecyclerView項上實現了單擊偵聽器, 但是現在我想打開一個片段,該片段將顯示有關所單擊盤子的更多信息,並且該片段應替換保存RecyclerView的片段,而不是 ViewPager的5個片段之一。
如何用RecyclerView項內部的單擊偵聽器(由ViewPager控制的片段內部)調用Dish信息片段,以便用Dish Information片段替換以前的ViewPager片段?
您需要制作一個新的片段,即菜品細節片段。 現在,在“回收者視圖”列表項上,單擊“ itemDetail”片段替換您現有的片段。 示例:-我假設您的容器視圖是“ R.id.fragmentContainer”,並且您正在此容器中加載片段。
現在,只需在recyclerView項目上調用此代碼,請單擊
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();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.