| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 23 | 24 | 25 | 26 | 27 | 28 | 29 |
| 30 |
- Registering an InstanceCreator with Gson for this type may fix this problem
- mac
- DispatchQueue
- data binding
- Android
- Eclipse
- 3rd part
- Framework
- Jetpack
- ndkVersion
- VM arguments
- NDK
- Swift
- EditText
- 3rd framework
- Java
- Compose
- defaultconfig
- gradle
- AOS
- Andorid
- buildconfigfield
- Chat GPT
- boot
- xcframework
- IOS
- BindingAdapter
- Kotlin
- retrofit
- arm-linux-androideabi
- Today
- Total
grape
[android]data binding 2 - BindingAdapter example EditText 본문
databinding send view & BindingAdapter
ViewModel
class ViewModel() : ViewModel() {
//If want update view data then use LiveData
//EditText support String simple
private val _text = MutableLiveData(String)
val data: LiveData = _text
//EditText not support Int Type need BindingAdapter
private val _num = MutableLiveData(String)
val num: LiveData = _num
layout
<data>
<variable
name="viewmodel"
type="com.test.name.ViewModel" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
...
//simple '{data}'
<EditText
android:text='@{viewmodel.text}'
/>
//need BindingAdapter Int
<EditText
android:text='@{viewmodel.num}'
/>
BindingAdapter
object EditTextDataBindingAdapter{
//EditText Int Type BindingAdapter
//need to static
@JvmStatic
//binding target "android:text"
@BindingAdapter("android:text")
// function name is user define
fun setText(view: TextView, text: Int)
{
view.text = text.toString()
}
}
'dev > aos' 카테고리의 다른 글
| [android]data binding 4 - app custom attribute (0) | 2023.10.12 |
|---|---|
| [android]data binding 3 - Two-way data binding & BindingAdapter example EditText (0) | 2023.10.12 |
| [android]data binding 1 - simple example EditText (0) | 2023.10.10 |
| [kotlin] event interface channel 활용 (0) | 2023.10.09 |
| [AudioRecord] API (0) | 2023.10.09 |