Carlos Bedoy
02/05/2021, 1:34 AMkotlinx.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..
<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:
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?
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
FunkyMuse
02/05/2021, 10:17 AMHenry
02/09/2021, 1:26 PM