Skip to content

Commit

Permalink
[Fix] 데이터바인딩 Step.01 수정
Browse files Browse the repository at this point in the history
build.gradle 수정, invalidateAll() 제거, 글루코드 제거, binding 전역변수 수정

Related to : #2, #6
  • Loading branch information
hyooosong committed Jan 1, 2021
1 parent 4d33f0d commit e3515fd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 23 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ android {
kotlinOptions {
jvmTarget = '1.8'
}
dataBinding {
enabled = true
buildFeatures{
dataBinding = true
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

<EditText
android:id="@+id/input_changed_profile"
Expand Down

0 comments on commit e3515fd

Please sign in to comment.