Reputation: 23
I am making Master/Detail flow activity in Kotlin. I have mismatch problem with fragments becuase in one activity I need android.support.v4.app.Fragment and in other android.app.Fragment. I implemented my own detail fragment and inherited from android.support.v4.app.Fragment to fix mismatch in supportFragmnet transaction from ListActivity
if (mTwoPane) {
val fragment = GraphDetailFragment().apply {
arguments = Bundle().apply {
putString(GraphDetailFragment.ARG_ITEM_ID, item.id)
}
}
supportFragmentManager
.beginTransaction()
.replace(R.id.graph_detail_container, fragment)
.commit()
}
But then I have mismatch in fragmentManager from DetailActivity
val fragment = GraphDetailFragment().apply {
arguments = Bundle().apply {
putString(GraphDetailFragment.ARG_ITEM_ID,
intent.getStringExtra(GraphDetailFragment.ARG_ITEM_ID))
}
}
fragmentManager.beginTransaction()
.add(R.id.graph_detail_container, fragment)
.commit()
and console throws :
None of the following functions can be called with the arguments supplied: public abstract fun add(p0: Fragment!, p1: String!): FragmentTransaction! defined in android.app.FragmentTransaction public abstract fun add(p0: Int, p1: Fragment!): FragmentTransaction! defined in android.app.FragmentTransaction
Is there any simple way how to fix this?
Upvotes: 2
Views: 783
Reputation: 17854
Make DetailActivity
extend AppCompatActivity
, and then use supportFragmentManager
in it.
You'll also need to fix your AppTheme in styles.xml. Make sure that the parent
attribute points to Theme.AppCompat
or Theme.AppCompat.Light
.
Upvotes: 3