티스토리 뷰
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:background="#FFBB11"
tools:context=".MainActivity">
<TextView
android:id="@+id/tvName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="James Kim"
android:textSize="30dp"
android:textStyle="bold" />
<Button
android:id="@+id/btnLong"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="혀가 긴 개발자"
android:textSize="20dp"
android:textStyle="bold"
android:layout_marginTop="30dp"/>
<Button
android:id="@+id/btnShort"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="혀가 길지 않은 개발자"
android:textSize="20dp"
android:textStyle="bold" />
</LinearLayout>

MainActivity.kt
package com.jwsoft.kotlinproject
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Observer
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
private var liveName: MutableLiveData<String> = MutableLiveData()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
liveName.observe(this, Observer {
tvName.text = it
})
btnLong.setOnClickListener { liveName.value = "혀가 긴 개발자" }
btnShort.setOnClickListener { liveName.value = "혀가 길지 않은 개발자" }
}
}

'Android > Kotlin' 카테고리의 다른 글
| [Kotlin] DataBinding + LiveData + BindingAdapter (0) | 2020.07.09 |
|---|---|
| [Kotlin] DataBinding + LiveData (0) | 2020.07.09 |
| [Kotlin] DataBinding (0) | 2020.07.09 |
| [Kotlin] ViewPager2 + FragmentStateAdapter (0) | 2020.07.06 |
| [Kotlin] CoordinatorLayout + AppBarLayout + Toolbar + RecyclerView (0) | 2020.07.04 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- java
- Livedata
- View
- 안드로이드 #코틀린 #Android #Kotlin
- 안드로이드
- 혀가 길지 않은 개발자
- JSONObject
- ViewModel
- CoordinatorLayout
- handler
- recyclerview
- ViewPager2
- 코틀린
- James Kim
- MVVM
- DataBinding
- Kotlin
- fragment
- XML
- TabLayout
- 자바
- Architecture Pattern
- JSONArray
- Intent
- ArrayList
- coroutine
- Android
- Design Pattern
- activity
- Vue.js #Vue.js + javascript
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
글 보관함