Компонент "Навигация" - не создан класс "Маршруты" - PullRequest
0 голосов
/ 17 октября 2019

У меня есть фрагмент A, где действие начинается с фрагмента B, который должен получить аргумент. Когда я пытаюсь установить аргумент перед навигацией, класс FragmentADirections не может быть разрешен. Дело в том, что у меня есть фрагмент C, идущий к D с аргументом, и это хорошо работает для этих двух.

Фрагмент класса A ('EntrainementAction'):

    package com.example.androidsportsomveille.Fragments;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.navigation.Navigation;

import com.example.androidsportsomveille.Classes.Entrainement;
import com.example.androidsportsomveille.R;

public class EntrainementAction extends Fragment {

    private Entrainement entrainement;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_entrainement_action, container, false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        this.entrainement = EntrainementActionArgs.fromBundle(getArguments()).getMyEntrainement();

        // Remplis le layout avec les données de l'enrainement
        populateLayout();

        // Aller à la gestion de l'entrainement
        Button btnGestion = view.findViewById(R.id.btnGestionEntrainement);
        btnGestion.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // Set de l'argument puis navigation
                EntrainementActionDirections.ActionEntrainementActionToEntrainementGestion action =
                        EntrainementActionDirections.actionEntrainementActionToEntrainementGestion(entrainement);
                Navigation.findNavController(view).navigate(action);
            }
        });
    }

    public void populateLayout() {
        TextView txtNom = getView().findViewById(R.id.txtNomEntrainement);
        txtNom.setText(this.entrainement.getNom());
    }
}

Появляется ошибкав «btnGestion.setOnClickListener», где «EntrainementActionDirections» не может быть разрешена. Обратите внимание, что у меня есть хорошо сгенерированный другой класс Directions.

Мой файл nav_graph.xml:

<?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/entrainementListe">

    <fragment
        android:id="@+id/entrainementListe"
        android:name="com.example.androidsportsomveille.Fragments.EntrainementListe"
        android:label="fragment_entrainement_liste"
        tools:layout="@layout/fragment_entrainement_liste" >
        <action
            android:id="@+id/action_entrainementListe_to_entrainementNouveau"
            app:destination="@id/entrainementNouveau" />
        <action
            android:id="@+id/action_entrainementListe_to_entrainementAction"
            app:destination="@id/entrainementAction" />
    </fragment>

    <fragment
        android:id="@+id/entrainementNouveau"
        android:name="com.example.androidsportsomveille.Fragments.EntrainementNouveau"
        android:label="fragment_entrainement_nouveau"
        tools:layout="@layout/fragment_entrainement_nouveau" >
        <action
            android:id="@+id/action_entrainementNouveau_to_entrainementGestion"
            app:destination="@id/entrainementGestion" />
    </fragment>
    <fragment
        android:id="@+id/entrainementAction"
        android:name="com.example.androidsportsomveille.Fragments.EntrainementAction"
        android:label="fragment_entrainement_action"
        tools:layout="@layout/fragment_entrainement_action" >
        <argument
            android:name="myEntrainement"
            app:argType="com.example.androidsportsomveille.Classes.Entrainement" />
        <action
            android:id="@+id/action_entrainementAction_to_entrainementGestion"
            app:destination="@id/entrainementGestion" />
    </fragment>
    <fragment
        android:id="@+id/entrainementGestion"
        android:name="com.example.androidsportsomveille.Fragments.EntrainementGestion"
        android:label="fragment_entrainement_gestion"
        tools:layout="@layout/fragment_entrainement_gestion" >
        <action
            android:id="@+id/action_entrainementGestion_to_entrainementAction"
            app:destination="@id/entrainementAction" />
        <argument
            android:name="myEntrainement"
            app:argType="com.example.androidsportsomveille.Classes.Entrainement" />
    </fragment>
</navigation>

Фрагменты 'entrainementAction' и 'entrainementGestion' не имеют класса Directions, сгенерированного в то время как 'entrainementListe' и'entrainementNouveau' есть. Все xml-файлы фрагментов существуют.

1 Ответ

0 голосов
/ 17 октября 2019

После обеденного перерыва я запустил Android Studio, а затем генерируются мои классы направлений. Я не знаю, почему я не мог использовать их раньше.

...