質問するログイン新規登録

回答編集履歴

1

せっかくなので、背景色を変えてみた。

2020/06/17 14:19

投稿

katsuko
katsuko

スコア3605

answer CHANGED
@@ -13,6 +13,7 @@
13
13
  import android.view.ViewGroup
14
14
  import android.view.LayoutInflater
15
15
  import android.widget.Button
16
+ import android.graphics.Color
16
17
 
17
18
  class MainActivity : AppCompatActivity()
18
19
  {
@@ -62,6 +63,7 @@
62
63
  val item = this.items[position]
63
64
  val textView: TextView = viewHolder.itemView.findViewById(android.R.id.text1)
64
65
  textView.setText(item.label + " " + item.count.toString())
66
+ viewHolder.itemView.setBackgroundColor(if (item.count % 2 == 0) Color.RED else Color.GREEN)
65
67
  }
66
68
 
67
69
  override fun getItemCount() : Int
@@ -85,5 +87,6 @@
85
87
  ```
86
88
 
87
89
  (勉強がてら初めてkotlinで書いたので、kotlinの文法は参考にしないように(笑))
90
+ (編集: せっかくなので、背景色を変えてみた)
88
91
 
89
92
  後は`notifyItemChanged`でググれば他にも情報が出てくると思います。