<?xml version="1.0" encoding="utf-8"?>
<navigation 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:id="@+id/nav_graph"
app:startDestination="@id/restaurantListFragment">
<fragment
android:id="@+id/scanQRFragment"
android:name="com.example.dine.ui.view.home.scan_qr.ScanQRFragment"
android:label="fragment_scan_q_r"
tools:layout="@layout/fragment_scan_q_r" />
<fragment
android:id="@+id/restaurantListFragment"
android:name="com.example.dine.ui.view.home.restaurants.RestaurantListFragment"
android:label="fragment_restaurant_list"
tools:layout="@layout/fragment_restaurant_list" >
<action
android:id="@+id/action_restaurantListFragment_to_restaruntDetailFragment"
app:destination="@id/restaruntDetailFragment"
app:popUpTo="@id/restaurantListFragment" />
</fragment>
<fragment
android:id="@+id/myPlateFragment"
android:name="com.example.dine.ui.view.home.my_plate.MyPlateFragment"
android:label="fragment_my_plate"
tools:layout="@layout/fragment_my_plate" />
<fragment
android:id="@+id/accountFragment"
android:name="com.example.dine.ui.view.home.account.AccountFragment"
android:label="fragment_account"
tools:layout="@layout/fragment_account" />
<fragment
android:id="@+id/restaruntDetailFragment"
android:name="com.example.dine.ui.view.restaurant_detail.RestaruntDetailFragment"
android:label="RestaruntDetailFragment"
tools:layout="@layout/fragment_restarunt_detail" />
</navigation>
这是我用于此导航片段的导航图文件。
private fun onItemSelected() {
findNavController().navigate(R.id.action_restaurantListFragment_to_restaruntDetailFragment)
}
我在某个动作上调用了 onItemSelected()方法,任何帮助都将非常有用。谢谢
从餐厅列表导航到RestaurantDetail片段时,就像这样。很久以来我一直在遭受这个问题的困扰