From e3515fd328a48bc83f75e27673f3ef40bf697d98 Mon Sep 17 00:00:00 2001 From: hyooosong Date: Fri, 1 Jan 2021 12:26:23 +0900 Subject: [PATCH] =?UTF-8?q?[Fix]=20=EB=8D=B0=EC=9D=B4=ED=84=B0=EB=B0=94?= =?UTF-8?q?=EC=9D=B8=EB=94=A9=20Step.01=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit build.gradle 수정, invalidateAll() 제거, 글루코드 제거, binding 전역변수 수정 Related to : #2, #6 --- app/build.gradle | 4 +-- .../practicegitanddatabinding/MainActivity.kt | 31 +++++++------------ app/src/main/res/layout/activity_main.xml | 2 +- 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 16316db..cdc254d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -31,8 +31,8 @@ android { kotlinOptions { jvmTarget = '1.8' } - dataBinding { - enabled = true + buildFeatures{ + dataBinding = true } } diff --git a/app/src/main/java/sotp/semina/practicegitanddatabinding/MainActivity.kt b/app/src/main/java/sotp/semina/practicegitanddatabinding/MainActivity.kt index 3496829..99dfc4b 100644 --- a/app/src/main/java/sotp/semina/practicegitanddatabinding/MainActivity.kt +++ b/app/src/main/java/sotp/semina/practicegitanddatabinding/MainActivity.kt @@ -12,37 +12,28 @@ import com.bumptech.glide.Glide import sotp.semina.practicegitanddatabinding.databinding.ActivityMainBinding class MainActivity : AppCompatActivity() { - private lateinit var binding: ActivityMainBinding - var profilename = "profileName" - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - binding = DataBindingUtil.setContentView(this, R.layout.activity_main) - binding.mainActivity = this - initView() - } + val binding : ActivityMainBinding = DataBindingUtil.setContentView(this, R.layout.activity_main) - private fun initView() { - initProfileImage() - setProfileName(DEFAULT_USER_NAME) - addButtonClickEvent() + initProfileImage(binding.imageProfileImage) + setProfileName(binding.textProfileName, DEFAULT_USER_NAME) + addButtonClickEvent(binding) } - - private fun initProfileImage() { - Glide.with(this) + private fun initProfileImage(imageView: ImageView) { + Glide.with(imageView.context) .load(IMAGE_URL) - .into(binding.imageProfileImage) + .into(imageView) } - private fun setProfileName(content:String) { - profilename = content - binding.invalidateAll() + private fun setProfileName(profileName:TextView, content:String) { + profileName.text = content } - private fun addButtonClickEvent() { + private fun addButtonClickEvent(binding : ActivityMainBinding) { binding.buttonProfileChangeButton.setOnClickListener { - setProfileName(getEditTextToString(findViewById(R.id.input_changed_profile))) + setProfileName(binding.textProfileName, getEditTextToString(binding.inputChangedProfile)) } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 1bf6122..6b61693 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -34,7 +34,7 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/image_profile_image" - tools:text="@{mainActivity.profilename}" /> + tools:text="Profile Name" />