mirror of
https://github.com/Skysamara/android-kotlin-fundamentals-apps.git
synced 2025-12-06 06:16:03 +00:00
Task: Add conditional navigation
This commit is contained in:
parent
8d1891dc0d
commit
aa3d64ff29
@ -23,6 +23,7 @@ import android.view.ViewGroup
|
|||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.databinding.DataBindingUtil
|
import androidx.databinding.DataBindingUtil
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
|
import androidx.navigation.findNavController
|
||||||
import com.example.android.navigation.databinding.FragmentGameBinding
|
import com.example.android.navigation.databinding.FragmentGameBinding
|
||||||
|
|
||||||
class GameFragment : Fragment() {
|
class GameFragment : Fragment() {
|
||||||
@ -98,10 +99,10 @@ class GameFragment : Fragment() {
|
|||||||
setQuestion()
|
setQuestion()
|
||||||
binding.invalidateAll()
|
binding.invalidateAll()
|
||||||
} else {
|
} else {
|
||||||
// We've won! Navigate to the gameWonFragment.
|
view.findNavController().navigate(R.id.action_gameFragment_to_gameWonFragment)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Game over! A wrong answer sends us to the gameOverFragment.
|
view.findNavController().navigate(R.id.action_gameFragment_to_gameOverFragment)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,5 +18,22 @@
|
|||||||
android:id="@+id/gameFragment"
|
android:id="@+id/gameFragment"
|
||||||
android:name="com.example.android.navigation.GameFragment"
|
android:name="com.example.android.navigation.GameFragment"
|
||||||
android:label="GameFragment"
|
android:label="GameFragment"
|
||||||
tools:layout="@layout/fragment_game"/>
|
tools:layout="@layout/fragment_game">
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_gameFragment_to_gameOverFragment"
|
||||||
|
app:destination="@id/gameOverFragment" />
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_gameFragment_to_gameWonFragment"
|
||||||
|
app:destination="@id/gameWonFragment" />
|
||||||
|
</fragment>
|
||||||
|
<fragment
|
||||||
|
android:id="@+id/gameOverFragment"
|
||||||
|
android:name="com.example.android.navigation.GameOverFragment"
|
||||||
|
android:label="fragment_game_over"
|
||||||
|
tools:layout="@layout/fragment_game_over" />
|
||||||
|
<fragment
|
||||||
|
android:id="@+id/gameWonFragment"
|
||||||
|
android:name="com.example.android.navigation.GameWonFragment"
|
||||||
|
android:label="fragment_game_won"
|
||||||
|
tools:layout="@layout/fragment_game_won" />
|
||||||
</navigation>
|
</navigation>
|
||||||
Loading…
x
Reference in New Issue
Block a user