반응형
[Gradle 설정]
1
|
id 'kotlin-android-extensions'
|
cs |
<MainActivity>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
package com.cookandroid.myapplication
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
title = "MainActivity"
btnNewActivity.setOnClickListener {
if(btnSecond.isChecked) startActivity(Intent(applicationContext, Second::class.java))
if(btnThird.isChecked) startActivity(Intent(applicationContext, Third::class.java))
}
}
}
|
cs |
<Second>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
package com.cookandroid.myapplication
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_second.*
class Second : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_second)
title = "Second"
btnReturn.setOnClickListener {
finish()
}
}
}
|
cs |
<Third>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
package com.cookandroid.myapplication
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_second.*
class Third : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_third)
title = "Third"
btnReturn.setOnClickListener {
finish()
}
}
}
|
cs |
<activity_main.xml>
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
|
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/btnSecond"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Second 액티비티"/>
<RadioButton
android:id="@+id/btnThird"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Third 액티비티"/>
</RadioGroup>
<Button
android:id="@+id/btnNewActivity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="새 화면 열기"/>
</LinearLayout>
|
cs |
<activity_second.xml>
1
2
3
4
5
6
7
8
9
10
11
12
13
|
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00FF00">
<Button
android:id="@+id/btnReturn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="돌아가기"/>
</LinearLayout>
|
cs |
<activity_third.xml>
1
2
3
4
5
6
7
8
9
10
11
12
13
|
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0000FF">
<Button
android:id="@+id/btnReturn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="돌아가기"/>
</LinearLayout>
|
cs |
반응형
'안드로이드 프로그래밍 > 코틀린' 카테고리의 다른 글
[코틀린을 활용한 안드로이드 프로그래밍] 7장 직접 풀어보기 7-3 (0) | 2022.04.22 |
---|---|
[코틀린을 활용한 안드로이드 프로그래밍] 10장 연습문제 5번 (0) | 2022.04.15 |
[코틀린을 활용한 안드로이드 프로그래밍] 4장 직접 풀어보기 4-3 (0) | 2022.04.15 |
[코틀린을 활용한 안드로이드 프로그래밍] 4장 직접 풀어보기 4-4 (0) | 2022.04.15 |
[코틀린을 활용한 안드로이드 프로그래밍] 7장 직접 풀어보기 7-2 (0) | 2022.04.15 |