developer.android.com/topic/libraries/data-binding/expressions?hl=ko
레이아웃 및 결합 표현식 | Android 개발자 | Android Developers
표현식 언어를 사용하면 뷰에 의해 전달된 이벤트를 처리하는 표현식을 작성할 수 있습니다. 데이터 결합 라이브러리는 레이아웃의 뷰를 데이터 객체와 결합하는 데 필요한 클래스를 자동으로
developer.android.com
핵심은 xmlns:bind 를 추가해주는 부분이다.
Main Layout
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bind="http://schemas.android.com/apk/res-auto">
...
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/name"
bind:user="@{user}"/>
<include layout="@layout/contact"
bind:user="@{user}"/>
</LinearLayout>
</layout>
Include Layout
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bind="http://schemas.android.com/apk/res-auto">
<data>
<variable name="user" type="com.example.User"/>
</data>
.....
</layout>
MainLayout 의 bind:user 그리고 include layout 의 variable name="user" 와 같이 맞춰줘야 한다.
반응형
'Dev > Android' 카테고리의 다른 글
| Android 진동 Vibrate (0) | 2021.04.15 |
|---|---|
| DataBindingUtil 오류 - <layout> 처리 (0) | 2021.04.08 |
| Android 기본 개념 정리 (0) | 2021.03.11 |
| [Step-By-Step] 하나씩, 안드로이드 개발 - RecyclerView (0) | 2021.02.26 |
| 안드로이드 업데이트가 거부후 재업로드 시간이 이렇게 오래걸려?! (0) | 2021.02.09 |