I'm trying to convert my MainActivity.kt into a Fragment, so the beggining of the code looks like this so far:
class MainActivity : Fragment() {
lateinit var mAdView : AdView private lateinit var progressDialog: ProgressDialog
private var selectedtype = "Ultra fast"
private val binding by lazy {
ActivityMainBinding.inflate(layoutInflater)
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.main_activity, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
//setContentView(binding.root)
progressDialog = ProgressDialog(this)
progressDialog.setCancelable(false)
progressDialog.setCanceledOnTouchOutside(false)
inIt()
MobileAds.initialize(this) {}
mAdView = view.findViewById(R.id.adView)
val adRequest = AdRequest.Builder().build()
mAdView.loadAd(adRequest)
getSupportActionBar()?.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM)
getSupportActionBar()?.setCustomView(R.layout.actionbar_title)
}
I have this error:
Type mismatch: inferred type is MainActivity but Context! was expected
Here:
progressDialog = ProgressDialog(this)
and here:
MobileAds.initialize(this) {}
and this error:
Unresolved reference: getSupportActionBar
here:
getSupportActionBar()?.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM)
getSupportActionBar()?.setCustomView(R.layout.actionbar_title)
how can I solve those?