![](/img/trans.png)
[英]How to show an onClick message when clicking on an item of my RecyclerView list?
[英]call fragments when clicking RecyclerView item and show them both in the same activity
由於我只從按鈕更改為 RecyclerView(並且按鈕工作得很好),我知道我的 java 代碼工作正常,所以現在我遇到了一個問題,因為單擊 RecyclerView 中的卡片會使用 FragmentManager 調用片段,但不是顯示它。 這是我的活動。xml 代碼。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".mainSearch" android:background="#f2f2f2"> <androidx.recyclerview.widget.RecyclerView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/recyclerView" android:orientation="horizontal" /> </androidx.constraintlayout.widget.ConstraintLayout> <fragment android:name="com.diamcom.blue.StoneCodeFragment" android:id="@+id/fragment_place" android:layout_width="match_parent" android:layout_height="match_parent"> </fragment> </LinearLayout>
我想知道我做錯了什么?
我認為您在這里遇到的問題是將 recyclerview 和片段作為寬度和高度的 match_parent。 我認為您可以做到這一點的一種方法是將包含 recyclerview 和片段的容器視圖包裝在框架布局中,並在單擊 recyclerview 中的任何卡片時使容器視圖消失。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.