简体   繁体   中英

Why Navigation Graph IDs are not listed in R.id?

I'm new to Android Navigation Component and I think I have everything ready for using it but when I try to navigate to another fragment using an action or a fragment id, the ids generated in the navigation graph xml file are not listed in R.id, so I can't use them to navigate.

This is the code I'm trying to execute:

view.findNavController().navigate(R.id.action_mainFragment_to_addFragment)

This is my nav_graph.xml file (autogenerated):

<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/mainFragment">
    <fragment android:id="@+id/mainFragment"
              android:name="com.example.nopesal.costlist.MainFragment"
              android:label="MainFragment"
              tools:layout="@layout/fragment_main">
        <action android:id="@+id/action_mainFragment_to_addFragment" app:destination="@id/addFragment"
                app:enterAnim="@anim/nav_default_enter_anim" app:exitAnim="@anim/nav_default_exit_anim"
                app:popEnterAnim="@anim/nav_default_pop_enter_anim" app:popExitAnim="@anim/nav_default_pop_exit_anim"/>
    </fragment>
    <fragment android:id="@+id/addFragment" android:name="com.example.nopesal.costlist.AddFragment"
              android:label="fragment_add" tools:layout="@layout/fragment_add"/>
</navigation>

As you can see, the ids are being generated with @+id/ and it's supposed to appear in R.id when I try to referentiate them, but they are not showing. It doesn´t matter if I try to reference an action or a fragment, neither are showing.

I've tried to clean the project, rebuild, change the gradle navigation implementation, change the id names, restart Android Studio... I can´t solve it. Also searching for tutorials, using R.id is he only way to referenciate them so I don´t know what I'm doing wrong.

If anyone have faced the same issue o knows the solution I would be completely grateful. Thank you so much.

I just solved it!

I just noticed i had this imports at the beggining of the file. I suppose that they have imported automatically after copy and paste the navigation code. Deleting this imports fixed the issue.

import android.R.attr.data
import android.R

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