Created
November 30, 2020 08:39
-
-
Save jaranflaath/5bfb681002c3120687a7a73a86ff43e4 to your computer and use it in GitHub Desktop.
This file contains 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
import android.view.View | |
import androidx.fragment.app.Fragment | |
import androidx.viewbinding.ViewBinding | |
abstract class BindingFragment<T : ViewBinding> : Fragment() { | |
private var _binding: T? = null | |
protected val views: T | |
get() = _binding!! | |
fun bindViews(binding: T): View { | |
_binding = binding | |
return binding.root | |
} | |
override fun onDestroyView() { | |
super.onDestroyView() | |
_binding = null | |
} | |
} |
This file contains 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
import android.os.Bundle | |
import android.view.LayoutInflater | |
import android.view.View | |
import android.view.ViewGroup | |
import no.gjensidige.android.databinding.FragmentFremtidBinding | |
class FremtidFragment : BindingFragment<FragmentFremtidBinding>() { | |
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | |
return bindViews(FragmentFremtidBinding.inflate(inflater, container, false)) | |
} | |
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | |
super.onViewCreated(view, savedInstanceState) | |
views.buttonFremtidLoaderBack.setOnClickListener(this::onBackButtonClicked) | |
} | |
private fun onBackButtonClicked(view: View) { | |
requireActivity().supportFragmentManager.popBackStackImmediate() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment