Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Kotlin & Android Data Binding Library
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
160
CameraX使ってみた
takuji31
0
310
kotlinx.datetime 使ってみた
takuji31
0
1.1k
HiltのCustom Componentについて
takuji31
0
380
java.timeをAndroidで使う
takuji31
0
200
KSPを使ってコード生成
takuji31
0
470
Kotlin Symbol Processing API (KSP) を使って Kotlin ア プリケーションの開発を効率化する
takuji31
1
3.2k
kotlinx.serialization
takuji31
0
690
kanmoba-returns-02.pdf
takuji31
0
290
Other Decks in Technology
See All in Technology
AI-DLCを “そのまま導入しなかった”話 ~組織に合わせてアジャストした 私たちの実践共有~
hiroramos4
PRO
1
430
作る力から、見極める力へ — AI時代に広がるエンジニアの価値と役割
rince
0
340
AWS Security Hub CSPMの成功・失敗体験
cmusudakeisuke
0
560
AIが自律的に回る開発ループを設計してチーム開発に組み込む
nekorush14
0
130
Lightning近況報告
kozy4324
0
220
コミュニティの有益性 ~JAWS Days 2026 での体験を通して~ / The Benefits of a Community ~Through My Experience at JAWS Days 2026~
seike460
PRO
0
280
レガシーな広告配信システムでのAI駆動開発/運用の挑戦
i16fujimoto
0
120
製造現場での生成AIの活用、およびエージェントAIの実装のあり方、AVEVAの取り組み
iotcomjpadmin
0
110
いまさら聞けない「仕様駆動開発入門」 〜AI活用時代の開発プロセスを考える〜
findy_eventslides
2
210
AIはどのように 組織のアジリティを変えるのか?
junki
4
1.4k
不要なレビューをAIにまかせて AIコーディングの環境改善を加速した
shoota
1
270
Comment regagner la souveraineté de vos données tout en étant payé grâce à Nostr !
rlifchitz
0
210
Featured
See All Featured
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.1k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
How to Think Like a Performance Engineer
csswizardry
28
2.7k
The SEO Collaboration Effect
kristinabergwall1
1
490
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
170
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.5k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.5k
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
140
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
240
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
620
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.5k
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