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
180
CameraX使ってみた
takuji31
0
340
kotlinx.datetime 使ってみた
takuji31
0
1.2k
HiltのCustom Componentについて
takuji31
0
460
java.timeをAndroidで使う
takuji31
0
220
KSPを使ってコード生成
takuji31
0
510
Kotlin Symbol Processing API (KSP) を使って Kotlin ア プリケーションの開発を効率化する
takuji31
1
3.3k
kotlinx.serialization
takuji31
0
720
kanmoba-returns-02.pdf
takuji31
0
320
Other Decks in Technology
See All in Technology
Consistency for mere mortals - A gentle guide to consistency
ufried
0
120
2026 Apache Flink Community Checkpoint
rmetzger
0
160
AIで選択肢が広がった組織設計の理想と現実
konifar
16
7.7k
公共システムAdventCalendar2026
toru_kubota
0
160
OneLakeをデータソースにした AI Search(Foundry IQ)の ライフサイクル管理
ryuseiiida
0
220
FinOpsを導入してマルチプロダクトのコスト最適化を実現する
kworkdev
PRO
0
120
Lint の層を組み直した話
bengo4com
3
310
なぜ東京にいる私が、新潟の技術コミュニティを運営するのか by 八雲慎之助
yakumo
0
220
企画からFlutter実装まで、1つの機能を一貫して開発したプロセスと成果物
khiroyuki1003
1
150
AIエージェントに業務知識を届ける仕組みづくり - Knowledge Catalogを活用した知識基盤の構築
hekuchan
0
120
Autonomous AI Lakehouse - Live AI Hubから始めるセキュアなAIデータ活用 -
oracle4engineer
PRO
3
190
【dbts2026】AIエージェントの 判断と探索を変える、 データベース エンジニアリング― 既存DBの処理と依存関係から作る、オペレーショナルオントロジー ―
shisyu_gaku
0
110
Featured
See All Featured
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
510
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
240
Between Models and Reality
mayunak
4
560
Building Better People: How to give real-time feedback that sticks.
wjessup
371
20k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
740
AI: The stuff that nobody shows you
jnunemaker
PRO
10
1.2k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
510
SEO for Brand Visibility & Recognition
aleyda
0
4.8k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.7k
BBQ
matthewcrist
90
10k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
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