Search code examples
androidkotlinmapshuawei-mobile-serviceshuawei-map-kit

Creating a Huawei Map programmatically


I'm creating programmatically a Huawei map, but despite MapFragment() is a child of Fragment class, the transaction add doesn't recognize it as a Fragment. Here's my code:

val transaction: FragmentTransaction = activity.supportFragmentManager.beginTransaction()
val mapFragment = MapFragment()
transaction.add(this.frame.id, mapFragment) ---> here is the problem
transaction.commit()

Someone knows the reason?


Solution

  • There are 2 different classes for showing map in fragment:

    1. MapFragment
    2. SupportMapFragment

    You must use correct one your activity.

    1. If Activity is just Activity and you use just FragmentManager - use MapFragment
    2. If activity is AppCompatActivity and you use SupportFragmentManager - use SupportMapFragment