Created
September 3, 2018 17:40
-
-
Save prasannajeet/9654836be54b8cd008e70cfa5da8579d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.praszapps.mysamplenavapp | |
import android.os.Bundle | |
import android.support.v4.app.Fragment | |
import android.view.LayoutInflater | |
import android.view.View | |
import android.view.ViewGroup | |
import androidx.navigation.fragment.findNavController | |
import kotlinx.android.synthetic.main.fragment_main.* | |
class MainFragment : Fragment() { | |
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, | |
savedInstanceState: Bundle?): View? { | |
// Inflate the layout for this fragment | |
return inflater.inflate(R.layout.fragment_main, container, false) | |
} | |
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | |
super.onViewCreated(view, savedInstanceState) | |
// Sending data from one fragment to another fragment | |
buttonWelcomeMe.setOnClickListener{ | |
val name = enterName.text.toString() | |
if(name.isEmpty()) { | |
enterName.error = "Please enter a name" | |
} else { | |
val action = MainFragmentDirections.actionMainFragmentToDestinationFragment() | |
action.setNameToShow(name) | |
findNavController().navigate(action) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment