Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

19 changes: 0 additions & 19 deletions BCSD_Assignment_2/app/src/main/res/layout/activity_main.xml

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions assignment_week_5/.idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions assignment_week_5/.idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
android:supportsRtl="true"
android:theme="@style/Theme.Test"
tools:targetApi="31">
<activity
android:name=".SecondActivity"
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="true">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.example.test

import android.content.Intent
import android.os.Bundle
import android.widget.Button
import android.widget.TextView
import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity

class MainActivity : AppCompatActivity() {

private var count = 0
private lateinit var countTextView: TextView

private val activityLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

registerForActivityResult 따로 빼주셔서 관리 했네요 👍

if (result.resultCode == RESULT_OK) {
val randomValue = result.data?.getIntExtra("randomValue", count)
count = randomValue ?: count
countTextView.text = count.toString()
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

val toastButton: Button = findViewById(R.id.toastButton)
val countButton: Button = findViewById(R.id.countButton)
val randomButton: Button = findViewById(R.id.randomButton)
countTextView = findViewById(R.id.countTextView)

toastButton.setOnClickListener {
Toast.makeText(this, "Toast 메시지 출력", Toast.LENGTH_SHORT).show()
}

countButton.setOnClickListener {
count++
countTextView.text = count.toString()
}

randomButton.setOnClickListener {
val intent = Intent(this, SecondActivity::class.java)
intent.putExtra("count", count)
activityLauncher.launch(intent)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.example.test

import android.app.Activity
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.TextView
import kotlin.random.Random

class SecondActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_second)

val count = intent.getIntExtra("count", 0)

val randomValue = Random.nextInt(0, count + 1)

val randomTextView: TextView = findViewById(R.id.randomTextView)
randomTextView.text = randomValue.toString()

val backButton: Button = findViewById(R.id.backButton)
backButton.setOnClickListener {
val resultIntent = Intent().apply {
putExtra("randomValue", randomValue)
}
setResult(Activity.RESULT_OK, resultIntent)
finish()
}
}
}
45 changes: 45 additions & 0 deletions assignment_week_5/app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
tools:context=".MainActivity">

<TextView
android:id="@+id/countTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:textSize="24sp"/>

<Button
android:id="@+id/toastButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Toast"
app:layout_constraintTop_toBottomOf="@id/countTextView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>

<Button
android:id="@+id/countButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Count"
app:layout_constraintTop_toBottomOf="@id/toastButton"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>

<Button
android:id="@+id/randomButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Random"
app:layout_constraintTop_toBottomOf="@id/countButton"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
28 changes: 28 additions & 0 deletions assignment_week_5/app/src/main/res/layout/activity_second.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
tools:context=".SecondActivity">

<TextView
android:id="@+id/randomTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24sp"
tools:text="랜덤 번호 생성"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>

<Button
android:id="@+id/backButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Back"
app:layout_constraintTop_toBottomOf="@id/randomTextView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>
File renamed without changes.
File renamed without changes.
File renamed without changes.