Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Kotlin & Android Data Binding Library
Search
Takuji Nishibayashi
March 30, 2016
Technology
3.4k
6
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Kotlin & Android Data Binding Library
Takuji Nishibayashi
March 30, 2016
More Decks by Takuji Nishibayashi
See All by Takuji Nishibayashi
compose-hot-reload を試そうとした話
takuji31
0
170
CameraX使ってみた
takuji31
0
330
kotlinx.datetime 使ってみた
takuji31
0
1.2k
HiltのCustom Componentについて
takuji31
0
450
java.timeをAndroidで使う
takuji31
0
220
KSPを使ってコード生成
takuji31
0
500
Kotlin Symbol Processing API (KSP) を使って Kotlin ア プリケーションの開発を効率化する
takuji31
1
3.3k
kotlinx.serialization
takuji31
0
720
kanmoba-returns-02.pdf
takuji31
0
310
Other Decks in Technology
See All in Technology
Kiro Crewで「みのるん式」仕事術やってみた
minorun365
PRO
3
930
フロントエンドカンファレンス関西2026 - 速すぎるUIに、待ち時間を
teamlab
PRO
0
210
Tofu-Controller lightning talk @ Containerday 2026
gionn
0
130
古い指輪から広がった JAVA コミュニティ とのつながり
yamad
0
130
スプシの手作業からの解脱 ~更新はClaude Codeに、見せ方と使い方はGASアプリに任せる~
kentarofujii
0
160
Code for Security プロジェクト紹介 2026年10月
yu23ki14
0
120
Metadata - Section 1: HTML Basics
mohab1
0
130
夫婦で子育てするための育児標準化
codmoninc
PRO
0
480
AIにシークレットを見せない、WSL2で安全な開発環境
yazm
0
320
Webの常識が通じないHTMLメールのダークモード
teamlab
PRO
0
140
今さら理解するウェブフォントver.2026
takanorip
3
940
パスキーの自動テストはどこまでいけるのか
teamlab
PRO
0
300
Featured
See All Featured
What's in a price? How to price your products and services
michaelherold
247
13k
Abbi's Birthday
coloredviolet
4
10k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
430
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
890
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
820
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
46k
Between Models and Reality
mayunak
4
500
Chasing Engaging Ingredients in Design
codingconduct
0
370
Code Review Best Practice
trishagee
74
20k
A Soul's Torment
seathinner
8
3.8k
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
480
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
2
330
Transcript
Kotlin & Android Data Binding Library @takuji31
@takuji31 (Takuji Nishibayashi) Application Engineer at Hatena
Loves Kotlin
Kotlin 1.0.1-2 released
Android Data Binding Library
Official binding library for Android
Android Studio support
One way binding support
Two way binding support latest version
Can use with Kotlin
Define binding using layout XML
Auto generate binding class
Define binding <layout> <data> <import type="android.view.View" /> <variable name=“user" type="jp.takuji31.kotlindatabinding.DataClassActivity.User"
/> <variable name=“randomButtonClickListener” type="android.view.View.OnClickListener" /> </data> <RelativeLayout> <TextView android:text="Name : "/> <TextView android:text="@{user.name}" tools:text="namename" /> <TextView android:text="Birthday : " android:visibility="@{user.birthDay != null ? View.VISIBLE : View.GONE}" /> <TextView android:text=“@{user.birthDay}" tools:text="1970/01/01" android:visibility="@{user.birthDay != null ? View.VISIBLE : View.GONE}” /> <Button android:onClick="@{randomButtonClickListener}"/> </RelativeLayout> </layout>
Using binding class DataClassActivity : AppCompatActivity() { data class User(val
name: String, val birthDay: String?) var users = listOf( User(name = "takuji31", birthDay = "1987/03/01"), User(name = "takuji32", birthDay = "1987/03/02"), User(name = "takuji33", birthDay = "1987/03/03"), User(name = "takuji24884", birthDay = null) ) val binding: ActivityDataClassBinding by lazy { DataBindingUtil.setContentView<ActivityDataClassBinding>(this, R.layout.activity_data_class) } override fun onCreate(savedInstanceState: Bundle?) { binding.user = users.last() binding.randomButtonClickListener = View.OnClickListener { binding.user = users[0] users = users.drop(1) + binding.user } } }
No more (ViewClass)findById(R.id.viewId)
Define binding <layout> <android.support.v7.widget.RecyclerView android:id="@+id/recyclerView" android:layout_width="match_parent" android:layout_height="match_parent"/> </layout>
Field access class MainActivity : AppCompatActivity() { val binding :
ActivityMainBinding by lazy {DataBindingUtil.setContentView<ActivityMainBinding>(this, R.layout.activity_main)} override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding.recyclerView.layoutManager = LinearLayoutManager(this) } }
Property observer
Observable data class class Counter : BaseObservable() { @get:Bindable var
count : Int = 0 set(value) { field = value notifyPropertyChanged(BR.count) } }
Define binding <layout> <data> <variable name=“counter" type=“…PropertyObserverActivity.Counter” /> <variable name="buttonClickListener"
type="android.view.View.OnClickListener" /> </data> <LinearLayout> <TextView android:text="@{@string/count_format(counter.count)}"/> <Button android:onClick=“@{buttonClickListener}" /> </LinearLayout> </layout>
Change value class PropertyObserverActivity : AppCompatActivity() { val binding :
ActivityPropertyObserverBinding by lazy { DataBindingUtil.setContentView( this, R.layout.activity_property_observer ) } override fun onCreate(savedInstanceState: Bundle?) { val counter = Counter() binding.counter = counter binding.buttonClickListener = View.OnClickListener { counter.count += 1 } } }
Binding adapter
Define binding adapter object Adapters { @JvmStatic @BindingAdapter("android:text") fun convertZonedDateTimeToString
(textView: TextView, zonedDateTime : ZonedDateTime) { val timeString = zonedDateTime.format( DateTimeFormatter.ofPattern("yyyy/MM/dd/ HH:mm:SS")) textView.text = timeString } }
Value converter
Issues with Kotlin
Can’t find converter written with Kotlin
Use Java
example : github.com/ takuji31/KotlinDataBinding
Enjoy Data Binding Life