Skip to content

Commit

Permalink
[Feat] 데이터바인딩 Step.02 실습
Browse files Browse the repository at this point in the history
Step.02 dataBinding Use_DataClass

Related to : #2, #6
  • Loading branch information
hyooosong committed Dec 31, 2020
1 parent 32f7852 commit 4893f19
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import android.widget.ImageView
import androidx.databinding.BindingAdapter
import com.bumptech.glide.Glide

/*TODO step2 바인딩 어뎁터 생성
* Glide로 이미지를 띄워주는 바인딩 어뎁터를 만들어주세요
* 뷰에서 사용할 어트리뷰트 이름은 image로 합니다.*/
object BindingAdapter {

@BindingAdapter("image")
@JvmStatic
fun loadImage(imageView: ImageView, url: String) {
Glide.with(imageView.context)
.load(url)
.into(imageView)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package sotp.semina.practicegitanddatabinding
import android.os.Bundle
import android.widget.EditText
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.BindingAdapter
import androidx.databinding.DataBindingUtil
import sotp.semina.practicegitanddatabinding.databinding.ActivityMainBinding

Expand All @@ -12,7 +13,8 @@ class MainActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
val binding: ActivityMainBinding =
DataBindingUtil.setContentView(this, R.layout.activity_main)
/*TODO step3 유저 데이터를 binding 변수에 넣어서 뷰에서 사용할 수 있도록 합니다.*/

binding.userProfile = UserData(IMAGE_URL, DEFAULT_USER_NAME)
addButtonClickEvent(binding)
}

Expand Down
9 changes: 5 additions & 4 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
xmlns:tools="http://schemas.android.com/tools">

<data>
<!--TODO step1 데이터 클래스 결합-->
<variable
name="userProfile"
type="sotp.semina.practicegitanddatabinding.UserData" />
</data>

<!--TODO step3 아래를 유저 데이터로 결합해주세요-->
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand All @@ -21,7 +22,7 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:src="@mipmap/ic_launcher" />
app:image="@{userProfile.userImage}" />

<TextView
android:id="@+id/text_profile_name"
Expand All @@ -33,7 +34,7 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/image_profile_image"
tools:text="profile name" />
tools:text="@{userProfile.userName}" />

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

0 comments on commit 4893f19

Please sign in to comment.