Skip to content

Commit

Permalink
[feat/#4] week2 - xml / essential(필수) : 홈화면 구현 (마이페이지 intent 정보 띄우기)
Browse files Browse the repository at this point in the history
  • Loading branch information
nagaeng committed Apr 18, 2024
1 parent 81e878f commit 0762bc2
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 16 deletions.
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ android {
buildFeatures {
viewBinding true
}
buildFeatures {
dataBinding true
}
}

dependencies {
Expand Down
18 changes: 16 additions & 2 deletions app/src/main/java/com/sopt/now/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,22 @@ class MainActivity : AppCompatActivity() {
true
}

R.id.menu_mypage-> {
replaceFragment(MyPageFragment())
R.id.menu_mypage -> {
val id = intent.getStringExtra("id")
val password = intent.getStringExtra("password")
val nickname = intent.getStringExtra("nickname")

// MyPageFragment로 데이터 전달
val bundle = Bundle().apply {
putString("id", id)
putString("password", password)
putString("nickname", nickname)
}

val myPageFragment = MyPageFragment()
myPageFragment.arguments = bundle

replaceFragment(myPageFragment) // 수정된 부분
true
}

Expand Down
35 changes: 28 additions & 7 deletions app/src/main/java/com/sopt/now/MyPageFragment.kt
Original file line number Diff line number Diff line change
@@ -1,20 +1,41 @@
package com.sopt.now

import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.Fragment
import com.sopt.now.databinding.FragmentHomeBinding

import androidx.recyclerview.widget.LinearLayoutManager
import com.sopt.now.databinding.FragmentMypageBinding
class MyPageFragment: Fragment() {
private lateinit var binding: FragmentHomeBinding

private var _binding: FragmentMypageBinding? = null
private val binding get() = _binding!!
private lateinit var friendListAdapter: FriendListAdapter //
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return super.onCreateView(inflater, container, savedInstanceState)
): View {
_binding = FragmentMypageBinding.inflate(inflater, container, false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

val id = arguments?.getString("id")
val password = arguments?.getString("password")
val nickname = arguments?.getString("nickname")

Log.d("MyPageFragment", "ID: $id, Password: $password, Nickname: $nickname")

view.findViewById<TextView>(R.id.tvId).text = "아이디: $id"
view.findViewById<TextView>(R.id.tvPassword).text = "비밀번호: $password"
view.findViewById<TextView>(R.id.tvNickname).text = "닉네임: $nickname"
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
}
}
34 changes: 27 additions & 7 deletions app/src/main/res/layout/fragment_mypage.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<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">

<TextView
android:id="@+id/tvHome"
android:id="@+id/tvNickname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="마이페이지화면"
android:textSize="30sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:textSize="35sp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
android:layout_marginTop="190dp"
android:layout_marginStart="50dp"/>

<TextView
android:id="@+id/tvId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
app:layout_constraintTop_toBottomOf="@id/tvNickname"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginTop="60dp"
android:layout_marginStart="50dp"/>

<TextView
android:id="@+id/tvPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
app:layout_constraintTop_toBottomOf="@id/tvId"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginTop="10dp"
android:layout_marginStart="50dp"/>

</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit 0762bc2

Please sign in to comment.