Hi everyone! I’m facing a weird issue, we used to...
# android
c
Hi everyone! I’m facing a weird issue, we used to use
kotlinx.synthetic
, (yeah! but is deprecated now), hence we start to migrate to viewBinding (honestly much better), but I’m facing next issue. I have a fragment such contains a MapFragment itself like this..
Copy code
<androidx.cardview.widget.CardView
    android:visibility="visible"
    .....
    app:layout_constraintTop_toTopOf="parent">

    <fragment
        android:id="@+id/onTheWayMap"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</androidx.cardview.widget.CardView>
Before with
kotlinx.syntheti
we only invoke following lines:
Copy code
override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? = inflater.inflate(R.layout.a_fragment, container, false)


val mapFragment = childFragmentManager.findFragmentById(R.id.map) as SupportMapFragment?
        mapFragment?.getMapAsync { //mapFragments never null
            googleMap = it
            ...
Since we’re migrating to
viewBinding
, keeping same code above, mapFragment always is null, anyone here had faced same issue?, do you guys know how to fixed?, what can be wrong?
Copy code
private val binding by lazy {
        FragmentOnTheWayBinding.inflate(LayoutInflater.from(context))
    }
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? = binding.root


val mapFragment = childFragmentManager.findFragmentById(R.id.map) as SupportMapFragment?
        mapFragment?.getMapAsync { //always null
            googleMap = it
f
You can't make the binding a lazy in the fragment and inflate it using the layout inflater provided by the context, it's not the same as the fragment's https://www.funkymuse.dev/2020/11/view-binding-for-lazy.html
👀 1
h
I have the base class use for ViewBinding in fragment, if you want, please feel free to take it https://gist.github.com/nphau/b177447b5323f93da1f62d7e75e29840