일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
- Swift
- ndkVersion
- 새마을금고
- Mac
- ChatGPT
- kotlin
- ndk r24
- Android
- 예금
- 3rd framework
- arm-linux-androideabi
- Data Binding
- Android Studio
- audio record
- Andorid
- 용산 호반써밋 에이디션
- MG더뱅킹정기예금
- 달러예금
- 사전청약
- KB
- gradle
- RETROFIT
- BindingAdapter
- EditText
- 고금리
- ios
- java
- JetPack
- 청약
- CHAT GPT
- Today
- Total
pear
[android]data binding 1 - simple example EditText 본문
simple data binding
https://developer.android.com/jetpack/androidx/releases/databinding
gradle
android {
...
buildFeatures {
dataBinding true
}
}
Activity
//connect activity & binding & viewmodel
class NameActivity : AppCompatActivity() {
private val viewModel: ViewModel by viewModels()
//auto generate ActivityNameBinding
private lateinit var binding : ActivityNameBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(this, R.layout.activity_name)
binding.viewmodel = viewModel
binding.lifecycleOwner = this
}
ViewModel
class ViewModel() : ViewModel() {
//If want update view data then use LiveData
//EditText support String simple
private val _text = MutableLiveData(String)
val text: LiveData = _text
layout
<data>
<variable
name="viewmodel"
type="com.test.name.ViewModel" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
...
//simple '{data}'
<EditText
android:text='@{viewmodel.text}'
/>
'android > kotlin' 카테고리의 다른 글
[android]data binding 5 - mistake error (0) | 2023.06.01 |
---|---|
[android]data binding 4 - app custom attribute (0) | 2023.06.01 |
[android]data binding 2 - BindingAdapter example EditText (0) | 2023.06.01 |
[android]data binding 3 - Two-way data binding & BindingAdapter example EditText (0) | 2023.06.01 |
[kotlin] event interface channel 활용 (0) | 2023.05.24 |