Reputation: 23
I'm trying to make a simple apartment rental app for a school project, but I have two problems that have stumped me. Here is the code for the DetailActivity.kt file:
package com.example.project.ui.screens
import android.os.Bundle
import androidx.activity.ComponentActivity
import com.bumptech.glide.Glide
import com.example.project.data.Apartment
import com.example.project.databinding.ActivityDetailBinding
class DetailActivity : ComponentActivity() {
private lateinit var binding:ActivityDetailBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityDetailBinding.inflate(layoutInflater)
setContentView(binding.root)
val apartment: Apartment? = intent.getParcelableExtra("APARTMENT")
apartment?.let {
binding.textViewName.text = it.apartmentName
binding.textViewLocation.text= it.apartmentLocation
binding.textViewPrice.text = "$${it.apartmentPrice}"
binding.textViewDescription.text = it.apartmentDescription
Glide.with(this).load(it.apartmentImageUrl).into(binding.textViewImage)
}
}
}
I get the errors: Type mismatch: inferred type is Parcelable? but Apartment? was expected Type mismatch: inferred type is Parcelable! but Apartment? was expected
When I tried changing type of 'Apartment?' to 'Parcelable?', like so:
val apartment: Parcelable? = intent.getParcelableExtra("APARTMENT")
apartment?.let {
binding.textViewName.text = it.apartmentName
binding.textViewLocation.text= it.apartmentLocation
binding.textViewPrice.text = "$${it.apartmentPrice}"
binding.textViewDescription.text = it.apartmentDescription
Glide.with(this).load(it.apartmentImageUrl).into(binding.textViewImage)
}
This results in getParcelableExtra becoming deprecated (crossed out in Android Studio) and all the values apartmentName, apartmentLocation, apartmentPrice, apartmentDescription and apartmentImageUrl becoming unresolved references.
Also, 'with' in 'Glide.with(this)' becomes crossed out saying 'with(Activity): RequestManager' is deprecated'.
How do I fix all of these issues to make the code function properly? Also, if there are any subsitutes I can use for some of the lines of code, that would be a big help. Thanks.
Upvotes: 0
Views: 40