es.davy.ai

Preguntas y respuestas de programación confiables

¿Tienes una pregunta?

Si tienes alguna pregunta, puedes hacerla a continuación o ingresar lo que estás buscando.

Gráfico de navegación abre otro fragmento.

Pregunta

Tengo una aplicación simple en la que intento abrir otro fragment al hacer clic en un botón.

Mi grafo de navegación

<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/app_navigation"
    app:startDestination="@id/homeFragment"></p>

<pre><code><fragment
    android:id="@+id/homeFragment"
    android:name="com.mine.parsexml.HomeFragment"
    android:label="fragment_home"
    tools:layout="@layout/fragment_home" >

    <action
        android:id="@+id/action_homeFragment_to_playerFragment"
        app:destination="@id/playerFragment" />
</fragment>
<fragment
    android:id="@+id/playerFragment"
    android:name="com.mine.parsexml.PlayerFragment"
    android:label="fragment_player"
    tools:layout="@layout/fragment_player" />
</code></pre>

<p></navigation>

Este es mi onClick en el fragmento

Vinculación.playVideos.setOnClickListener {
        HomeFragmentDirections.actionHomeFragmentToPlayerFragment()
    }

Este es el diseño de la actividad

<androidx.constraintlayout.widget.ConstraintLayout 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<em>width="match</em>parent"
    android:layout<em>height="match</em>parent"
    tools:context=".MainActivity">

<pre><code><androidx.fragment.app.FragmentContainerView
    android:id="@+id/nav_host_fragment"
    android:name="androidx.navigation.fragment.NavHostFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:defaultNavHost="true"
    app:navGraph="@navigation/app_navigation" />
</code></pre>

</androidx.constraintlayout.widget.ConstraintLayout>

Cuando hago clic en el botón, el fragmento del reproductor no se abre.

Tags:  , , ,

Answer

Comments are closed.