下面的代码是从Java转换而来的,其中一些代码没有转换过来。我试图让这一切都转变为Kotlin。
override fun onBindViewHolder(holder: PersonViewHolder, position: Int) {
holder.mImage.setImageResource(mPersonList[position].personImage)
holder.mTitle.text = mPersonList[position].personName
holder.mCardView.setOnClickListener {
//Unresolved reference:Java
val intent = intent(this, DetailActivity::class.java)
//Only safe (?.) or non-null asserted(!!.) calls are allowed on a nullable receiver of type intent?
intent.putExtra("Title", mPersonList[holder.adapterPosition].personName)
intent.putExtra("Description", mPersonList[holder.adapterPosition].personDescription)
intent.putExtra("Image", mPersonList[holder.adapterPosition].personImage)
mContext.startActivity(intent)
}
}
答案 0 :(得分:0)
使用此代码
holder.mCardView.setOnClickListener {
val intent = Intent(this, DetailActivity::class.java)
intent.putExtra("Title", mPersonList[holder.adapterPosition].personName)
intent.putExtra("Description", mPersonList[holder.adapterPosition].personDescription)
intent.putExtra("Image", mPersonList[holder.adapterPosition].personImage)
mContext?.startActivity(intent)
}