Skip to content

Commit

Permalink
[nunu/#23] feat: 5주차 구현2
Browse files Browse the repository at this point in the history
- 메모 앱 구현
- mainActivity에서 Search Fragment 대신 Memo Activity 보여주기
  • Loading branch information
Ssamssamukja committed May 14, 2024
1 parent 50c76bd commit 38e6019
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 0 deletions.
6 changes: 6 additions & 0 deletions UMC_6th/app/src/main/java/com/example/umc_6th/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,16 @@ class MainActivity : AppCompatActivity() {
true
}
R.id.fragment_search -> {
// MemoActivity 시작
val intent = Intent(this, MemoActivity::class.java)
startActivity(intent)
true
/* search fragment
supportFragmentManager.beginTransaction().replace(
R.id.main_container,
SearchFragment()
).commit()
*/
true
}
R.id.fragment_locker -> {
Expand Down
45 changes: 45 additions & 0 deletions UMC_6th/app/src/main/java/com/example/umc_6th/MemoActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.example.umc_6th
import android.app.AlertDialog
import android.os.Bundle
import android.widget.EditText
import androidx.appcompat.app.AppCompatActivity


class MemoActivity : AppCompatActivity() {
private var editTextNote: EditText? = null
private var savedNoteContent = ""

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_memo)
editTextNote = findViewById<EditText>(R.id.editTextMemo)
}

override fun onResume() {
super.onResume()
if (!savedNoteContent.isEmpty()) {
editTextNote!!.setText(savedNoteContent)
}
}

override fun onPause() {
super.onPause()
savedNoteContent = editTextNote!!.text.toString() // 현재 EditText 내용 저장
}

override fun onRestart() {
super.onRestart()
AlertDialog.Builder(this) // 다이얼로그 생성
.setTitle("재작성 확인")
.setMessage("메모를 새로 작성하시겠습니까?")
.setPositiveButton("") { dialog, which ->
editTextNote!!.setText("")
}
.setNegativeButton(
"아니오"
) { dialog, which ->
}
.show()
}
}

27 changes: 27 additions & 0 deletions UMC_6th/app/src/main/res/layout/activity_memo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white">

<EditText
android:id="@+id/editTextMemo"
android:layout_width="match_parent"
android:layout_height="0dp"
android:hint="메모를 입력하세요"
app:layout_constraintBottom_toTopOf="@+id/btnMemoConfirm"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/btnMemoConfirm"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="확인"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
15 changes: 15 additions & 0 deletions UMC_6th/app/src/main/res/layout/activity_memo_confirm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
android:background="@color/white">

<TextView
android:id="@+id/textViewNote"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="메모 내용"
android:textSize="18sp"/>

</LinearLayout>

0 comments on commit 38e6019

Please sign in to comment.