Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.8 kB
30
Indexable
package com.ort.classnavigationtest.fragments

import androidx.lifecycle.ViewModelProvider
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.EditText
import android.widget.TextView
import androidx.navigation.findNavController
import androidx.navigation.fragment.NavHostFragment.Companion.findNavController
import androidx.navigation.fragment.findNavController
import com.google.android.material.snackbar.Snackbar
import com.ort.classnavigationtest.R

class FirstFragment : Fragment() {
    lateinit var v : View

    lateinit var btnNavigate : Button
    lateinit var label : TextView
    lateinit var inputName : EditText
    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        v = inflater.inflate(R.layout.fragment_first, container, false)

        btnNavigate = v.findViewById(R.id.btnNavigation)
        label = v.findViewById(R.id.txtLabel1)
        inputName = v.findViewById(R.id.inpuName)

        return v
    }

    override fun onStart() {
        super.onStart()

        btnNavigate.setOnClickListener {

           // val action  = FirstFragmentDirections.actionFirstFragmentToSecondFragment("Hello")
           // findNavController().navigate(action)
            var inputText = inputName.text.toString()  // leo el texto del usuario

            if(inputText.isNotEmpty()){
                label.text = inputText // lo muestro en el label
            }
            else{
               Snackbar.make(v,"El campo esta vacio",Snackbar.LENGTH_SHORT).show()
            }


        }
    }


}