Home > Net >  Android Navigation does not run
Android Navigation does not run

Time:03-07

I am working with a rent calcualtions app, and having problems with navigation actions between to fragments. I have a back button but when I try to call the action nothing happends. It's strange becouse my other back button between fragsments works. Do you guys see any problem with my code?

I am going to implement Data-binding, ViewModul, LiveData, ev. LiveData Transformations.

Please know that this prosject is ongoing so all code is not set up yet.

annuitetPlanFragment.kt

package com.example.lnognedbetalingsplan

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.TextView
import androidx.navigation.fragment.findNavController
import kotlin.math.pow

class annuitetPlanFragment : Fragment() {

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {



        val viewAnnuitetPlan = inflater.inflate(R.layout.fragment_annuitet_plan, container, false)
        val buttonTilbake = viewAnnuitetPlan.findViewById<Button>(R.id.tilbakeTilAnnuitet)


        buttonTilbake.setOnClickListener {
            findNavController().navigate(R.id.action_annuitetPlanFragment_to_annuitetFragment)
        }


        var loanNumber = 200000
        var rent = 3.6
        var terminer = 12
        var r = rent / 100

        var x = 1   (1   r).pow(terminer)
        var y = x / rent
        var terminbelop = loanNumber / y
        var avdrag = terminer * terminbelop - loanNumber

        return inflater.inflate(R.layout.fragment_annuitet_plan, container, false)
    }
}

navigation.xml

 <fragment
        android:id="@ id/annuitetPlanFragment"
        android:name="com.example.lnognedbetalingsplan.annuitetPlanFragment"
        android:label="fragment_annuitet_plan"
        tools:layout="@layout/fragment_annuitet_plan" >
        <action
            android:id="@ id/action_annuitetPlanFragment_to_annuitetFragment"
            app:destination="@id/annuitetFragment"
            app:popUpTo="@id/annuitetFragment"
            app:popUpToInclusive="true" />
        <argument
            android:name="belop"
            app:argType="integer" />
    </fragment>

enter image description here

CodePudding user response:

in annuitetPlanFragment.kt change return onCreateView() function to

return viewAnnuitetPlan
  • Related