我希望在單擊 fragment_mudur_home.xml 中的 Yetki_modulu_cardView 時打開 fragment_yetki.xml 檔案。如何在 MudurHomeFragment.kt 類中執行此操作?
MudurHomeFragment.kt
fragment_home_mudur
uj5u.com熱心網友回復:
首先,您必須在 mobile_navigation 頁面中創建一個操作。像這樣
`<fragment
android:id="@ id/titleFragment"
android:name="com.dheeraj.guessbro.title.TitleFragment"
android:label="title_fragment"
tools:layout="@layout/title_fragment">
**<action
android:id="@ id/action_titleFragment_to_gameFragment"
app:destination="@id/gameFragment" />**
</fragment>'
然后轉到 MudurHomeFragment.kt 檔案并使用以下代碼:
binding.yetki_modulu_cardView.setOnClickListener { findNavController(this).navigate(R.id.action_titleFragment_to_gameFragment) }
如果您不使用視圖系結,則可以先使用 findViewById 定義變數,然后使用 clickListener。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/406322.html
標籤:
