Android - Navigating

2022. 4. 14. 09:52IT/안드로이드

반응형

01. Adding the Navigation Graph Resource

02. Adding the NavHostFragment

03. Adding Fragments to the Navigation Graph

04. Connecting Fragments in the Graph with Actions

05. Create onClickListner

06. Find Navigation Controller

07. Navigate with our Action

++

여기서 View, Navigation 을 좀 더 간편하게 쓸 수 있는 방법!

Android KTX가 있다. 

override fun onCreateView(
    inflater: LayoutInflater, container: ViewGroup?,
    savedInstanceState: Bundle?): View? {
    // Inflate the layout for this fragment
    val binding:FragmentTitleBinding = DataBindingUtil.inflate(
        inflater, R.layout.fragment_title,container, false)

    binding.playButton.setOnClickListener (
        Navigation.createNavigateOnClickListener(R.id.action_titleFragment_to_gameFragment2)
    )
    
    /*
    binding.playButton.setOnClickListener { view: View ->
        Navigation.findNavController(view).navigate(R.id.action_titleFragment_to_gameFragment2)
    }
    */

    return binding.root
    //return inflater.inflate(R.layout.fragment_title2, container, false)
}

위의 binding.PlayButton.setOnClickListener 를 좀 더 간결 하게 쓸 수 있다. 

하면서 느끼는건데... 언어도 똑같이 암기해야한다. 문법 암기하는것처럼... ㅠㅠ 

 

 

728x90
반응형