-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhoneBookActivity.kt
65 lines (52 loc) · 2.02 KB
/
PhoneBookActivity.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.example.myapplication
import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.widget.LinearLayout
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
class PhoneBookActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_phone_book)
val phoneBook = createFakePhoneBook(30)
createPhoneBookList(phoneBook)
}
fun createFakePhoneBook(fakeNumber: Int = 10, phoneBook : PhoneBook = PhoneBook()) : PhoneBook {
for (i in 0 until fakeNumber) {
phoneBook.addPerson(
Person(name = ""+ i + "번째 사람", number = "" + i + "번째 사람의 전화번호")
)
}
return phoneBook
}
fun createPhoneBookList(phoneBook: PhoneBook) {
val layoutInflate = LayoutInflater.from(this@PhoneBookActivity)
val container = findViewById<LinearLayout>(R.id.phonebook_ist_container)
for (i in 0 until phoneBook.personList.size) {
val view = layoutInflater.inflate(R.layout.phonebook_item, null)
val personNameView = view.findViewById<TextView>(R.id.person_name)
personNameView.setText(phoneBook.personList.get(i).name)
addSetOnClickListener(phoneBook.personList.get(i), view)
container.addView(view)
}
}
fun addSetOnClickListener(person: Person, view : View) {
view.setOnClickListener {
val intent = Intent(this@PhoneBookActivity, PhoneBookDetailActivity::class.java)
intent.putExtra("name", person.name)
intent.putExtra("number", person.number)
startActivity(intent)
}
}
}
class PhoneBook() {
//전화번호부
val personList = ArrayList<Person> ()
fun addPerson(person : Person) {
personList.add(person)
}
}
class Person(val name: String, var number: String) {
}