Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

143
Views
¿Por qué necesitamos 2 variables de "enlace" cuando trabajamos con ViewBinding en Android?

Veamos el ejemplo oficial:

 private var _binding: ResultProfileBinding? = null // This property is only valid between onCreateView and // onDestroyView. private val binding get() = _binding!! override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { _binding = ResultProfileBinding.inflate(inflater, container, false) val view = binding.root return view } override fun onDestroyView() { super.onDestroyView() _binding = null }

¿Por qué hay 2 variables similares: _binding y binding ? ¿Por qué no podemos usar una variable?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Esto es para tener una vista que no acepta valores NULL de la propiedad binding por conveniencia en el resto del código, pero aún tiene la posibilidad de administrar el valor real que acepta valores NULL en onCreateView / onDestroyView a través _binding .

El enfoque de lateinit en actividades es mejor, pero con lateinit no puede "restablecer" el enlace de nuevo a nulo, por lo que no es aplicable para fragmentos.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!