Skip to content

Commit

Permalink
[MOD/#8] 프래그먼트 초기화 함수 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
kangyuri1114 committed Oct 24, 2023
1 parent 2538239 commit 57aeaa6
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,7 @@ class BnvActivity : AppCompatActivity() {
binding = ActivityBnvBinding.inflate(layoutInflater)
setContentView(binding.root)

// 처음에 보여주어야 하는 프래그먼트를 변수로
val currentFragment = supportFragmentManager.findFragmentById(R.id.fcv_home)
// 만약 프래그먼트가 끼워지지 않았다면 프래그먼트메이저를 사용하여 끼워보기
if (currentFragment == null) {
supportFragmentManager.beginTransaction()
.add(R.id.fcv_home, HomeFragment())
.commit()
} // Fragment의 재생성과 newInstance() 알아보기
initialFragment(R.id.fcv_home, HomeFragment())

clickBnv()
}
Expand Down Expand Up @@ -69,4 +62,15 @@ class BnvActivity : AppCompatActivity() {
.replace(R.id.fcv_home, fragment)
.commit()
}

// 프래그먼트 초기화 함수
private fun initialFragment(containerViewId: Int, fragment: Fragment) {
val currentFragment = supportFragmentManager.findFragmentById(containerViewId)

if (currentFragment == null) {
supportFragmentManager.beginTransaction()
.add(containerViewId, Fragment())
.commit()
}
}
}

0 comments on commit 57aeaa6

Please sign in to comment.