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
320
kotlinx.datetime 使ってみた
takuji31
0
1.1k
HiltのCustom Componentについて
takuji31
0
440
java.timeをAndroidで使う
takuji31
0
220
KSPを使ってコード生成
takuji31
0
490
Kotlin Symbol Processing API (KSP) を使って Kotlin ア プリケーションの開発を効率化する
takuji31
1
3.3k
kotlinx.serialization
takuji31
0
710
kanmoba-returns-02.pdf
takuji31
0
300
Other Decks in Technology
See All in Technology
Genieを崇めよ
kameitomohiro
0
160
OpenTelemetry eBPF Instrumentationの舞台裏 / Behind the Scenes of OpenTelemetry eBPF Instrumentation
ymotongpoo
4
1.3k
SREは、MCPとAutopilotをこう使え!
kazumax55
3
850
顧客に向き合う開発組織へ。リアーキテクチャとフィーチャーチーム化で挑む組織改革
safie
0
2k
幾何アルゴリズムで なめらかなピン操作を / iOSDC Japan 2026 / smoothpin
kazumanagano
0
350
なぜ「決定性」が 決定的に重要なのか? Durable Execution 基盤の数理的理解 #serverlessjp / ServerlessDays Tokyo 2026
ytaka23
0
290
2026_devsumi_ozono.pdf
o3
3
510
[2026-09-11]SREは誰のもの?運用エンジニアが始める 「SRE領域への越境」とチームの進化の軌跡 〜Road to NEXT CRE
tosite
0
290
TinyGo 開発サイクルを高速化する:Go で作るエミュレータ入門
zozotech
PRO
1
740
データ_AIの事業の勝敗をわけるもの
nek0128
1
400
synctest時代のhttptest Go 1.27で変わるHTTPサーバテストの裏側 / go conference2026 synctest and httptest
budougumi0617
1
3k
AIによるクリエイティブ生成を行う上での試行錯誤
plaidtech
PRO
0
160
Featured
See All Featured
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
410
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.7k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
510
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
290
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
690
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
510
Navigating Weather and Climate Data
rabernat
0
520
Typedesign – Prime Four
hannesfritz
42
3.2k
YesSQL, Process and Tooling at Scale
rocio
174
15k
Marketing to machines
jonoalderson
1
5.8k
Evolving SEO for Evolving Search Engines
ryanjones
0
290
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
700
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