DB ํ๋ก์ ํธ
์๊ฐ์ ์ ๋ณด ๊ด๋ฆฌ
์ฃผ์ ๊ตฌ์ฑ
- ์ด 4๊ฐ์ ํ๋ฉด์ผ๋ก ๊ตฌ์ฑ๋จ
- ์ฑ์ ์๊ฐํ๋ ๋ฉ์ธ ํ๋ฉด
- ์๊ฐ์ ์ ๋ณด๋ฅผ ์ ๋ ฅํ๋ ํ๋ฉด
- ๊ฐ๋ณ ์๊ฐ์ ์ ๋ณด๋ฅผ ์ถ๋ ฅํ๋ ํ๋ฉด
- ๋ชจ๋ ์๊ฐ์ ์ ๋ณด๋ฅผ ์ถ๋ ฅํ๋ ํ๋ฉด
- SQLite ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ์ฌ์ฉ
- ์ถ๋ ฅํด์ผ ํ ๋ฐ์ดํฐ ์๊ฐ ์ ํด์ ธ ์์ง ์์ผ๋ฏ๋ก ๋์ ์ผ๋ก ๋ฐ์ดํฐ๋ฅผ ์ค์ ํจ
ํ์ผ ํธ์ง ์์
- ๋ฉ์ธ์กํฐ๋นํฐ
- MainActivity.kt / activity_main.xml / menu_main.xml
- ์๊ฐ์ ๋ฑ๋ก ์กํฐ๋นํฐ
- PersonnelReg.kt / activity_personnel_reg.xml/menu_personnel_reg.xml
- ์๊ฐ์ ์ ๋ณด ์กํฐ๋นํฐ
- PersonnelInfo.kt / activity_personnel_info.xml / menu_personnel_info.xml
- ์๊ฐ์ ๋ชฉ๋ก ์กํฐ๋นํฐ
- PersonnelList.kt / activity_personnel_list.xml / menu_personnel_list.xml
1. ๋ฉ์ธ ํ๋ฉด ์์ฑํ๊ธฐ
๋ฉ๋ด ๋ฆฌ์์ค ํ์ผ ์์ฑ
- ํ๋ก์ ํธ ์ฐฝ์์ res์์ ์ฐํด๋ฆญ ๋๋ ์๋๋ก์ด๋ ์คํ๋์ค ์๋จ ๋ฉ๋ด์์ File → New → Android Resource Directory ๋ฅผ ํด๋ฆญ
- res ํด๋ ์๋์ menu ๋๋ ํฐ๋ฆฌ๋ฅผ ์ ํํ๊ณ ์ฐํด๋ฆญ ๋๋ ์๋๋ก์ด๋ ์คํ๋์ค ์๋จ ๋ฉ๋ด์์ File → New → Menu resource file์ ํด๋ฆญํจ
์กํฐ๋นํฐ ์ถ๊ฐํ๊ธฐ
new > Activity > Empty Views Activity
- PersonnelInfo, PersonnelList, PersonnelReg ์์ฑ
๋ฉ์ธํ๋ฉด
์ต์ ๋ฉ๋ด
- ์๊ฐ์ ๋ชฉ๋ก๊ณผ ์๊ฐ์ ๋ฑ๋ก์ผ๋ก ๊ตฌ์ฑ
๋ฉ์ธ๋ฉ๋ด ํธ์ง
- ํ ์คํธ ๋ฆฌ์์ค ํธ์ง
- ๋ฉ๋ด์์ ์ฌ์ฉ๋ ์ด๋ฆ ์ถ๊ฐ – strings.xml
<resources>
<string name="app_name">StudentManagement</string>
<string name="action_home"> ํ </string>
<string name="action_list"> ์๊ฐ์ ๋ชฉ๋ก </string>
<string name="action_reg"> ์๊ฐ์ ๋ฑ๋ก </string>
<string name="action_remove"> ์ญ์ </string>
</resources>
์กํฐ๋นํฐ
- ์ต์ ๋ฉ๋ด
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean { // ๋ฉ๋ด
menuInflater.inflate(R.menu.menu_main, menu) // ์ธํ๋ ์ดํธ ์ฌ์ฉํ์ฌ ๋ฉ๋ด ๋ถ๋ฌ์ค๊ธฐ
return true
}
override fun onOptionsItemSelected(item: MenuItem): Boolean { // ๋ฉ๋ด ๋๋ฌ ํ๋ฉด ์ ํ(์ธํ
ํธ ์ฌ์ฉ)
when(item?.itemId) {
R.id.action_list -> {
val intent = Intent(this, PersonnelList::class.java)
startActivity(intent)
return true // ์ฑ๊ณต ์ true ๋ฐํ
}
R.id.action_reg -> {
val intent = Intent(this, PersonnelReg::class.java)
startActivity(intent)
return true // ์ฑ๊ณต ์ true ๋ฐํ
}
}
return super.onOptionsItemSelected(item)
}
}
2. ์๊ฐ์ ๋ฑ๋กํ๊ธฐ
์๊ฐ์ ์ ๋ณด ๋ฑ๋ก
- ์ฑ๋ช , ์ฑ๋ณ, ๋์ด, ์ ํ๋ฒํธ๋ฅผ ์ ๋ ฅ
- ์ ๋ ฅํ ๋ด์ฉ์ด Personnel ํ ์ด๋ธ์ ์ ์ฅ
- ๊ฐ๋ณ ์๊ฐ์ ์ ๋ณด ์กํฐ๋นํฐ๋ฅผ ํธ์ถ
๋ฉ๋ด ๊ตฌ์ฑ
- res > menu> New Resource File ์์ menu_personnel_reg.xml ์์ฑ
- ํ, ์๊ฐ์ ๋ชฉ๋ก
ํ๋ฉด ์์ฑํ๊ธฐ
- action_personnel_reg.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="100dp"
android:paddingRight="30dp"
android:paddingLeft="30dp"
tools:context=".PersonnelReg">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="60sp"
android:layout_height="wrap_content"
android:text="์ฑ๋ช
" />
<EditText
android:id="@+id/edtName"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="60sp"
android:layout_height="wrap_content"
android:text="์ฑ๋ณ" />
<RadioGroup
android:id="@+id/gender"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="@+id/male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="male" />
<RadioButton
android:id="@+id/female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="female" />
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="60sp"
android:layout_height="wrap_content"
android:text="๋์ด" />
<EditText
android:id="@+id/edtAge"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="60sp"
android:layout_height="wrap_content"
android:text="์ ํ๋ฒํธ" />
<EditText
android:id="@+id/edtTel"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/btnRegister"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="๋ฑ๋ก" />
</LinearLayout>
</LinearLayout>
DB ์ฌ์ฉํ๊ธฐ
- new > Kotlin File > DBManager ๋ผ๋ ์ด๋ฆ์ class ํ์ผ ์์ฑ
- SQLiteOpenHelper ํด๋์ค๋ฅผ ์์๋ฐ์ DBManager ํด๋์ค ์์ฑํ๊ธฐ
- onCreate(), onUpgrade() ๋ฉ์๋
โป ํด๋์ค ์์ ๋ฐ์ ๋ ์ค๋ฅ


class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean { // ๋ฉ๋ด
menuInflater.inflate(R.menu.menu_main, menu) // ์ธํ๋ ์ดํธ ์ฌ์ฉํ์ฌ ๋ฉ๋ด ๋ถ๋ฌ์ค๊ธฐ
return true
}
override fun onOptionsItemSelected(item: MenuItem): Boolean { // ๋ฉ๋ด ๋๋ฌ ํ๋ฉด ์ ํ(์ธํ
ํธ ์ฌ์ฉ)
when(item?.itemId) {
R.id.action_list -> {
val intent = Intent(this, PersonnelList::class.java)
startActivity(intent)
return true // ์ฑ๊ณต ์ true ๋ฐํ
}
R.id.action_reg -> {
val intent = Intent(this, PersonnelReg::class.java)
startActivity(intent)
return true // ์ฑ๊ณต ์ true ๋ฐํ
}
}
return super.onOptionsItemSelected(item)
}
}
์๊ฐ์ ๋ฑ๋ก ๊ธฐ๋ฅ ๊ตฌํํ๊ธฐ
- PersonnelReg.kt
- ์์ ฏ ๋ณ์ ๋ฑ๋กํ๊ธฐ
- ๋ฒํผ ํด๋ฆญ์ ๋ฆฌ์ค๋ ๊ตฌํ
- ์๊ฐ์ ์ ๋ณด DB์ ์ ์ฅ
์ต์ ๋ฉ๋ด ์ถ๊ฐํ๊ธฐ
class PersonnelReg : AppCompatActivity() {
lateinit var dbManager: DBManager
lateinit var sqlitedb: SQLiteDatabase
lateinit var btnResister: Button
lateinit var edtName: EditText
lateinit var edtAge: EditText
lateinit var edtTel: EditText
lateinit var rb_gender: RadioGroup
lateinit var rb_gender_m: RadioButton
lateinit var rb_gender_f: RadioButton
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_personnel_reg)
btnResister = findViewById(R.id.btnRegister)
edtName = findViewById(R.id.edtName)
edtAge = findViewById(R.id.edtAge)
edtTel = findViewById(R.id.edtTel)
rb_gender = findViewById(R.id.gender)
rb_gender_m = findViewById(R.id.male)
rb_gender_f = findViewById(R.id.female)
dbManager = DBManager(this, "personnelDB", null, 1) // DBManager ๊ฐ์ฒด ๋ฐ์์ค๊ธฐ
btnResister.setOnClickListener {
val str_name: String = edtName.text.toString()
var str_age: String = edtAge.text.toString()
val str_tel: String = edtTel.text.toString()
var str_gender: String = ""
if(rb_gender.checkedRadioButtonId == R.id.male) {
str_gender = rb_gender_m.text.toString()
}
if(rb_gender.checkedRadioButtonId == R.id.female) {
str_gender = rb_gender_f.text.toString()
}
sqlitedb = dbManager.writableDatabase // ์ฐ๊ธฐ ๊ฐ๋ฅํ ๋ฒ์ ์ผ๋ก DB ๊ฐ์ ธ์ค๊ธฐ
sqlitedb.execSQL("INSERT INTO personnel VALUES ('" + str_name +"', '" + str_gender +"', " + str_age +", '" + str_tel +"')")
sqlitedb.close()
val intent = Intent(this, PersonnelInfo::class.java)
intent.putExtra("intent_name", str_name)
startActivity(intent)
}
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean { // ๋ฉ๋ด
menuInflater.inflate(R.menu.menu_personnel_reg, menu) // ์ธํ๋ ์ดํธ ์ฌ์ฉํ์ฌ ๋ฉ๋ด ๋ถ๋ฌ์ค๊ธฐ
return true
}
override fun onOptionsItemSelected(item: MenuItem): Boolean { // ๋ฉ๋ด ๋๋ฌ ํ๋ฉด ์ ํ(์ธํ
ํธ ์ฌ์ฉ)
when(item?.itemId) {
R.id.action_home -> {
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
return true // ์ฑ๊ณต ์ true ๋ฐํ
}
R.id.action_list -> {
val intent = Intent(this, PersonnelList::class.java)
startActivity(intent)
return true // ์ฑ๊ณต ์ true ๋ฐํ
}
}
return super.onOptionsItemSelected(item)
}
}
3. ๊ฐ๋ณ ์๊ฐ์ ์ ๋ณด ์ถ๋ ฅํ๊ธฐ
๊ฐ๋ณ ์๊ฐ์ ์ ๋ณด ์ถ๋ ฅํ๊ธฐ
- ํน์ ์ธ๋ฌผ์ ์ฑ๋ช ์ ์ถ์ถํ๊ณ , DB ํ ์ด๋ธ์์ ํด๋น ์ธ๋ฌผ์ ์ถ์ถํด์ ์ถ๋ ฅํจ
- ์๊ฐ์ ๋ฑ๋ก ๋๋ ๋ชจ๋ ์๊ฐ์ ์ ๋ณด์์ ์ ํ๋จ
- ์ญ์ ๋ฉ๋ด ํด๋ฆญ ์ ํด๋น ์ธ๋ฌผ ์ ๋ณด๋ฅผ ํ ์ด๋ธ์์ ์ญ์ ํ๊ณ ์ ์ฒด ์๊ฐ์ ๋ชฉ๋ก์ผ๋ก ์ด๋ํจ
๋ฉ๋ด ๊ตฌ์ฑ
- menu_personnel_info.xml
- ํ, ์๊ฐ์ ๋ชฉ๋ก, ์๊ฐ์ ๋ฑ๋ก, ์ญ์
ํ๋ฉด ์์ฑํ๊ธฐ
- activity_personnel_info.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="100dp"
android:paddingRight="16dp"
android:paddingLeft="16dp"
tools:context=".PersonnelInfo">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="60sp"
android:layout_height="wrap_content"
android:text="์ฑ๋ช
" />
<TextView
android:id="@+id/edtName"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="60sp"
android:layout_height="wrap_content"
android:text="์ฑ๋ณ" />
<TextView
android:id="@+id/gender"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="60sp"
android:layout_height="wrap_content"
android:text="๋์ด" />
<TextView
android:id="@+id/edtAge"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="60sp"
android:layout_height="wrap_content"
android:text="์ ํ๋ฒํธ" />
<TextView
android:id="@+id/edtTel"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
๊ฐ๋ณ ์๊ฐ์ ์ ๋ณด ์ถ๋ ฅํ๊ธฐ
- Personnel_info.kt
โป value must be ≥ 0 but getcolumnindex can be ์ ๋ํ ์ค๋ฅ ํด๊ฒฐ
→ getColumnIndex ๋์ getColumnIndexOrThrow๋ก ์์ฑ
if(cursor.moveToNext()) {
str_gender = cursor.getString(cursor.getColumnIndexOrThrow("gender")).toString() // column ๊ฐ์ผ๋ก ์ธ๋ฑ์ค ์์์ค๊ธฐ
age = cursor.getInt(cursor.getColumnIndexOrThrow("age"))
str_tel = cursor.getString(cursor.getColumnIndexOrThrow("tel")).toString()
}
https://stackoverflow.com/questions/69053061/android-studio-value-must-be-%E2%89%A5-0
class PersonnelInfo : AppCompatActivity() {
lateinit var dbManager: DBManager
lateinit var sqlitedb: SQLiteDatabase
lateinit var tvName: TextView
lateinit var tvGender: TextView
lateinit var tvAge: TextView
lateinit var tvTel: TextView
lateinit var str_name: String
lateinit var str_gender: String
var age: Int = 0
lateinit var str_tel: String
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_personnel_info)
tvName = findViewById(R.id.edtName)
tvGender = findViewById(R.id.gender)
tvAge = findViewById(R.id.edtAge)
tvTel = findViewById(R.id.edtTel)
val intent = intent
str_name = intent.getStringExtra("intent_name").toString()
dbManager = DBManager(this, "personnelDB", null, 1) // DBManager ๊ฐ์ฒด ๋ฐ์์ค๊ธฐ
sqlitedb = dbManager.readableDatabase
var cursor: Cursor
cursor = sqlitedb.rawQuery("SELECT * FROM personnel WHERE name = '"+str_name+"';", null)
if(cursor.moveToNext()) {
str_gender = cursor.getString(cursor.getColumnIndexOrThrow("gender")).toString() // column ๊ฐ์ผ๋ก ์ธ๋ฑ์ค ์์์ค๊ธฐ
age = cursor.getInt(cursor.getColumnIndexOrThrow("age"))
str_tel = cursor.getString(cursor.getColumnIndexOrThrow("tel")).toString()
}
cursor.close()
sqlitedb.close()
dbManager.close()
tvName.text = str_name
tvGender.text = str_gender
tvAge.text = "" + age
tvTel.text = str_tel + "\n"
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean { // ๋ฉ๋ด
menuInflater.inflate(R.menu.menu_personnel_info, menu) // ์ธํ๋ ์ดํธ ์ฌ์ฉํ์ฌ ๋ฉ๋ด ๋ถ๋ฌ์ค๊ธฐ
return true
}
override fun onOptionsItemSelected(item: MenuItem): Boolean { // ๋ฉ๋ด ๋๋ฌ ํ๋ฉด ์ ํ(์ธํ
ํธ ์ฌ์ฉ)
when(item?.itemId) {
R.id.action_home -> {
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
return true // ์ฑ๊ณต ์ true ๋ฐํ
}
R.id.action_list -> {
val intent = Intent(this, PersonnelList::class.java)
startActivity(intent)
return true // ์ฑ๊ณต ์ true ๋ฐํ
}
R.id.action_reg -> {
val intent = Intent(this, PersonnelReg::class.java)
startActivity(intent)
return true // ์ฑ๊ณต ์ true ๋ฐํ
}
R.id.action_remove -> {
dbManager = DBManager(this, "personnelDB", null, 1) // DBManager ๊ฐ์ฒด ๋ฐ์์ค๊ธฐ
sqlitedb = dbManager.readableDatabase
sqlitedb.execSQL("DELETE FROM personnel WHERE name = '"+str_name+"';")
sqlitedb.close()
dbManager.close()
val intent = Intent(this, PersonnelList::class.java)
startActivity(intent)
return true // ์ฑ๊ณต ์ true ๋ฐํ
}
}
return super.onOptionsItemSelected(item)
}
}
4. ๋ชจ๋ ์๊ฐ์ ์ ๋ณด ์ถ๋ ฅํ๊ธฐ
๋ชจ๋ ์๊ฐ์ ์ ๋ณด ์ถ๋ ฅํ๊ธฐ
- DB ํ ์ด๋ธ์ ๋ฑ๋ก๋ ๋ชจ๋ ์ธ๋ฌผ ์ ๋ณด๋ฅผ ์ถ์ถํ์ฌ ํญ๋ชฉ๋ค์ ์ถ๋ ฅํจ
๋ฉ๋ด ๊ตฌ์ฑ
- menu_personnel_list.xml
- ํ, ์๊ฐ์ ๋ฑ๋ก
ํ๋ฉด ์์ฑํ๊ธฐ
- activity_personnel_list.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".PersonnelList">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/personnel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
</LinearLayout>
๋ชจ๋ ์๊ฐ์ ์ ๋ณด ์ถ๋ ฅํ๊ธฐ
- Personnel_list.kt
class PersonnelList : AppCompatActivity() {
lateinit var dbManager: DBManager
lateinit var sqlitedb: SQLiteDatabase
lateinit var layout: LinearLayout
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_personnel_list)
dbManager = DBManager(this, "personnelDB", null, 1)
sqlitedb = dbManager.readableDatabase
layout = findViewById(R.id.personnel)
var cursor: Cursor
cursor = sqlitedb.rawQuery("SELECT * FROM personnel", null)
var num: Int = 0
while (cursor.moveToNext()) {
var str_name = cursor.getString(cursor.getColumnIndexOrThrow("name")).toString() // column ๊ฐ์ผ๋ก ์ธ๋ฑ์ค ์์์ค๊ธฐ
var str_gender = cursor.getString(cursor.getColumnIndexOrThrow("gender")).toString()
var age = cursor.getInt(cursor.getColumnIndexOrThrow("age"))
var str_tel = cursor.getString(cursor.getColumnIndexOrThrow("tel")).toString()
var layout_item: LinearLayout = LinearLayout(this)
layout_item.orientation = LinearLayout.VERTICAL
layout_item.id = num
var tvName: TextView = TextView(this)
tvName.text = str_name
tvName.textSize = 30f
tvName.setBackgroundColor(Color.LTGRAY)
layout_item.addView(tvName)
var tvGender: TextView = TextView(this)
tvGender.text = str_gender
layout_item.addView(tvGender)
var tvAge: TextView = TextView(this)
tvAge.text = age.toString()
layout_item.addView(tvAge)
var tvTel: TextView = TextView(this)
tvTel.text = str_tel
layout_item.addView(tvTel)
layout_item.setOnClickListener {
val intent = Intent(this, PersonnelInfo::class.java)
intent.putExtra("intent_name", str_name)
startActivity(intent)
}
layout.addView(layout_item)
num++;
}
cursor.close()
sqlitedb.close()
dbManager.close()
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean { // ๋ฉ๋ด
menuInflater.inflate(R.menu.menu_personnel_list, menu) // ์ธํ๋ ์ดํธ ์ฌ์ฉํ์ฌ ๋ฉ๋ด ๋ถ๋ฌ์ค๊ธฐ
return true
}
override fun onOptionsItemSelected(item: MenuItem): Boolean { // ๋ฉ๋ด ๋๋ฌ ํ๋ฉด ์ ํ(์ธํ
ํธ ์ฌ์ฉ)
when(item?.itemId) {
R.id.action_home -> {
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
return true // ์ฑ๊ณต ์ true ๋ฐํ
}
R.id.action_reg -> {
val intent = Intent(this, PersonnelReg::class.java)
startActivity(intent)
return true // ์ฑ๊ณต ์ true ๋ฐํ
}
}
return super.onOptionsItemSelected(item)
}
}
์ต์ข