Skip to content

5.7. ๋ชฉํ‘œ

Seulgi Kim edited this page Jan 15, 2021 · 2 revisions

WrittenBy

๊ตฌํ˜„ ๋ฐฉ๋ฒ•

๋ชฉํ‘œ Main

(1) RecyclerView๋ฅผ ํ†ตํ•ด ๋ชฉํ‘œ ๋ฐ์ดํ„ฐ Display

๋ชฉํ‘œ Detail

(2) DailyFragment๋กœ๋ถ€ํ„ฐ Intent Action์„ ์ „๋‹ฌ๋ฐ›์•„ ์ˆ˜์ •์ธ์ง€ ์ฒ˜์Œ์ž‘์„ฑ์ธ์ง€ ์ฒ˜๋ฆฌ


๊ตฌํ˜„ ์ฝ”๋“œ

๋ชฉํ‘œ Main

(1) RecyclerView๋ฅผ ํ†ตํ•ด ๋ชฉํ‘œ ๋ฐ์ดํ„ฐ Display

  • fragment_goal.xml
        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/rv_goal"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_marginVertical="32dp"
            android:paddingHorizontal="16dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/tv_goal_num_alert"
            tools:listitem="@layout/item_keyword_goal"
            tools:itemCount="4"/>

๋ชฉํ‘œ Detail

(2) DailyFragment๋กœ๋ถ€ํ„ฐ Intent Action์„ ์ „๋‹ฌ๋ฐ›์•„ ์ˆ˜์ •์ธ์ง€ ์ฒ˜์Œ์ž‘์„ฑ์ธ์ง€ ์ฒ˜๋ฆฌ

  • DailyFragment.kt
    private fun startGoalDetailActivityWithAction(action: String, goal: Goal) {
        val intent: Intent = Intent(requireActivity(), GoalDetailActivity::class.java).apply {
            this.action = action
            putExtra("keyword", goal.keyword)
            putExtra("goal", goal.goal)
        }
        startActivity(intent)
    }
  • DailyGoalActivity.kt
    private fun getIntentData() {
        intentAction = intent.action
        intentKeyword = intent.getStringExtra("keyword")
        intentGoal = intent.getStringExtra("goal")
    }

    private fun initViewByAction() {
        when (intentAction) {
            "ADD" -> stateAdd()
            "MODIFY" -> stateModify()
        }
    }

    /* ๋ชฉํ‘œ ์„ค์ • */
    private fun stateAdd() {
        ...
    }

    /* ๋ชฉํ‘œ ์ˆ˜์ • */
    private fun stateModify() {
        ...
    }

์‹คํ–‰ ํ™”๋ฉด