Solution 1 :
I’m assuming you’re using androidx.navigation
. If your aren’t, have a look at this: https://developer.android.com/guide/navigation/navigation-getting-started
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
object : CountDownTimer(30000, 1000){
override fun onFinish() {
game_timer?.text = "Done"
activity.findNavController( R.id.your_nav_host_in_your_activity).navigate(R.id.your_target_fragment )
}
override fun onTick(millisUntilFinished: Long) {
game_timer?.text = "" + millisUntilFinished / 1000
}
}.start()
Problem :
I’m trying to make the fragment automatically redirect to another fragment once the timer has run out. How would I go about doing that? Thanks
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
object : CountDownTimer(30000, 1000){
override fun onFinish() {
game_timer?.text = "Done"
}
override fun onTick(millisUntilFinished: Long) {
game_timer?.text = "" + millisUntilFinished / 1000
}
}.start()
Comments
Comment posted by James Harden
Yes using navigation, But they all work through buttons, and I’m trying to get it to navigate without on click
Comment posted by Cory Roy
This should work, then if your time does. You’ll need to change the
Comment posted by James Harden
what would I have to put in the onFinish() to get it to redirecT? currently only have it to display done
Comment posted by Cory Roy
activity.findNavController( R.id.your_nav_host_in_your_activity).navigate(R.id.your_target_fragment )