๋น ๊ตฌ๋ฉ ์ฑ์ฐ๊ธฐ
[Android] ๊ธฐ๋ณธ ์ ๊ณต BindingAdapter
โญโญ๊ธฐ๋ก
2022. 10. 13. 18:33
๊ธฐ์กด์ ์ ๊ณตํ๋ ๊ธฐ๋ฅ์ธ๋ฐ ๋๋ง ๋ชจ๋ฅด๊ณ ์๋ก ๋ง๋๋ ์์ ์ ํผํ๊ณ ์ถ๋ค.
๊ธฐ๋ณธ์ ์ผ๋ก ์ ๊ณต๋๋ BindingAdapter๋ค์ ๊ตฌ์ฒด์ ์ธ ๋ช ์ธ๋ฅผ ๋ชฐ๋ผ์ ์ด๋ ๊ฒ ์ฐ๋ฉด๋์ง ์์๊น ์์ํ๊ณ ์ผ๋ค๊ฐ ๋น๋ ํ ์๋ชป๋๋ค๋ ๊ฒ์ ํ์ธํ๋ ์๊ณ ๋ ๋๊ณ ์ถ๋ค.
๋๋ณด๊ธฐ

ImageViewBindingAdapter ์ ๊ตฌํ ์ฌํญ
์ฝ์ง

android:src="@{๋๋ก์๋ธ๋ฆฌ์์ค}" ๋ผ ์ฐ๊ณ ๋น๋ ์๋ฌ๋ฌ์.
์ด ์ฝ๋๋ฅผ ํ์ธํ๊ณ android:src="@{context.getDrawable(๋๋ก์๋ธ๋ฆฌ์์ค)}" ๋ก ์ฐ๋ฉด ๋๋ค๋ ๊ฑธ ์.
androidx.databinding.adapters ํจํค์ง ์์ ์ด๋ฏธ ๊ตฌํ๋ BindingAdpater ํด๋์ค๋ค ์ด๋ฆ์ ์ด์ ์ผ ์์๋ค.
ํด๋น ์ฝ๋๋ฅผ ํ์ธํ๋๋ก
- ImageViewBindingAdapter
- TextViewBindingAdapter
- AutoCompleteTextViewBindingAdapter
- ViewGroupBindingAdapter
- AdapterViewBindingAdapter
- CompoundButtonBindingAdapter