forked from deveshp007/Android-App-Development
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP11.kt
32 lines (24 loc) · 1.02 KB
/
P11.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package com.example.myapplication
import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.ArrayAdapter
import android.widget.ListView
import androidx.constraintlayout.widget.ConstraintLayout
class ListViewEx : AppCompatActivity() {
lateinit var lst_view: ListView
lateinit var layoutmain: ConstraintLayout
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_list_view_ex)
lst_view = findViewById(R.id.lst_view)
layoutmain = findViewById(R.id.layoutMain)
val arr = arrayOf(Color.RED, Color.BLUE, Color.GRAY, Color.CYAN, Color.YELLOW)
val b = arrayOf("RED", "BLUE", "GRAY", "CYAN", "YELLOW")
val adapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, b)
lst_view.adapter = adapter
lst_view.setOnItemClickListener { adapterView, view, i, l ->
layoutmain.setBackgroundColor(arr[i])
}
}
}