1

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?

a_local_nobody
  • 7,947
  • 5
  • 29
  • 51

1 Answers1

1

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
mohax
  • 4,435
  • 2
  • 38
  • 85
  • Now I have an other question, I create a CustomSupportFragmentManager (child of SupportFragmentManager) to intercept onTouch Event, with a TouchableWrapper (child of FrameLayout), but never get the onTouchEvent in Huawei, for Google yes. Do you know why? – BraveQueen05 Feb 16 '21 at 17:31
  • Maybe you need to override `dispatchTouchEvent` in TouchableWrapper and manually pass MotionEvent to dispatchTouchEvent of mapView? – mohax Feb 16 '21 at 18:19
  • Check my question in here please, I posted some of my code https://stackoverflow.com/questions/66229963/huawei-map-inside-nested-scroll – BraveQueen05 Feb 16 '21 at 18:34