1. item click
class MainAdapter(
private val context: Context
) : RecyclerView.Adapter<MainAdapter.ViewHolder>() {
..이전코드들
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val item = SellerDB.sellerModelDB[position]
holder.bind(item)
holder.itemView.setOnClickListener {
val intent = Intent(context, DetailActivity::class.java)
intent.putExtra(SELLER, item)
context.startActivity(intent)
}
}
..이전코드들
}
//main에서
private val mainAdapter by lazy {
MainAdapter(this@MainActivity)
}
2.레이아웃의 기능
<TextView
android:id="@+id/item_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="12dp"
android:ellipsize="end"
android:maxLines="2"
android:text="제목이들어가는자리입니다.제목이들어가는자리입니다.제목이들어가는자리입니다."
android:textSize="18dp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/cardView"
app:layout_constraintTop_toTopOf="parent" />
이 부분은 이전에도 사용했던 부분이지만, 반복해서 잊지 않기 위함이다.
width나 height를 0dp로 설정하면, constraint를 해준 값들로 해당 값들이 자동으로 바뀐다.
따라서 필요에 따라 width와 height는 0dp로 지정하고 end start/혹은 top bottom으로 제어가 가능하다
따라서 이 기능을 잊지말자!
'개발노트 > Kotlin' 카테고리의 다른 글
9주차 1일 팀프로젝트-xml과 drawableResource 그리고 color (0) | 2023.09.04 |
---|---|
8주차 5일 fragment와 액티비티등 (0) | 2023.09.01 |
8주차 1일 Serializable 그리고 Parcelable (2) | 2023.08.28 |
7주차 4일 코틀린 문법들과 기타등등 (0) | 2023.08.24 |
7주차 3일 fragment에서 viewbinding과 fragment의 구?조? (0) | 2023.08.23 |