0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Kotlinのコードの備忘録(自分用)

Last updated at Posted at 2025-07-03

目次

文字列連結
binding
EpoxyRecyclerViewの一部にComposeを埋め込む
kotlinの公式が用意しているweb上の実行環境

文字列連結

CafeMenuListFragment.ktの指摘があった箇所
composableInterop(id = "key" + menu.id.toString, keys = arrayOf(menu.id),)

id = "key" + menu.id.toString

こっちの方がKotlinらしい記述です。
id = "key${menu.id.toString}"

binding

そもそも、自分は、bindingとfindViewByIdの違いが分かっていなかった。。。
bindingとfindViewByIdが頭の中でごちゃ混ぜになっていた。。。
findByIdを使う場合、各々のidに紐づけしなくてはいけなかった(それぞれのviewsごとにfindViewByIdを呼ぶことになる)。
しかし、viewBindingを使うと、viewの数だけfindByIdを呼ぶ必要が無い。

〇findViewById
IMG_0041.PNG

〇binding
IMG_0039.PNG

戻り値が無いのであれば、applyではなくwithを使った方がいいかも

参考サイト

EpoxyRecyclerViewの一部にComposeを埋め込む

実装時に参考にしたサイト

kotlinの公式が用意しているweb上の実行環境

参考サイト

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?