Slide 1

Slide 1 text

View Binding In Android 3.6

Slide 2

Slide 2 text

Hello Su Myat WTM Ambassador Lead Android Developer @devsumyat

Slide 3

Slide 3 text

Contents 1.WHY THIS TALK Because you can use ViewBindings in Android Studio 3.6 Canary11+ 2. ACCESSING VIEWS Let’s look up options what we have and evaluate them in terms of elegance, the compile time safety and the build speed impact. 3. HOW TO USE Go back findViewByID, then Data Binding and View Binding.

Slide 4

Slide 4 text

Why this talk? .

Slide 5

Slide 5 text

In Google IO 2019

Slide 6

Slide 6 text

Now is available

Slide 7

Slide 7 text

Before we go to ViewBinding, start first DataBinding

Slide 8

Slide 8 text

What’s Data Binding? - Declarative UI inside XML

Slide 9

Slide 9 text

What’s Data Binding? - Declarative UIs inside XML - Binding the gab between code and XML

Slide 10

Slide 10 text

What’s View Binding? - New API

Slide 11

Slide 11 text

View Binding? - New API - Similar Concept as DataBinding

Slide 12

Slide 12 text

ViewBinding/DataBinding can provide a nice way of directly calling views by id with just initializing one variable - the binding class.

Slide 13

Slide 13 text

How do we access Views on Android? .

Slide 14

Slide 14 text

Let’s look up options we have? Method Elegance Compile Type Safety Build Speed

Slide 15

Slide 15 text

Let’s look up options we have? Method Elegance Compile Type Safety Build Speed findViewById

Slide 16

Slide 16 text

Let’s look up options we have? Method Elegance Compile Type Safety Build Speed findViewById Data Binding

Slide 17

Slide 17 text

Let’s look up options we have? Method Elegance Compile Type Safety Build Speed findViewById Data Binding Butterknife

Slide 18

Slide 18 text

Let’s look up options we have? Method Elegance Compile Type Safety Build Speed findViewById Data Binding Butterknife Kotlin Synthethic

Slide 19

Slide 19 text

Let’s look up options we have? Method Elegance Compile Type Safety Build Speed findViewById Data Binding Butterknife Kotlin Synthethic ???

Slide 20

Slide 20 text

Let’s look up options we have? Method Elegance Compile Type Safety Build Speed findViewById Data Binding Butterknife Kotlin Synthethic View Binding

Slide 21

Slide 21 text

How to use? .

Slide 22

Slide 22 text

Sample App

Slide 23

Slide 23 text

let’s get steps back to old

Slide 24

Slide 24 text

In findVieById lateinit var likeCountTxt: TextView lateinit var likeBtn: Button override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) loveCountTxt = findViewById(R.id.txt_love_count) likeBtn = findViewById(R.id.btn_like) viewModel.likes.observe(this, Observer { likeCountTxt.text = "${it}" }) likeBtn.setOnClickListener { viewModel.onLike() } }

Slide 25

Slide 25 text

In DataBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val binding : ActivityMainBinding = DataBindingUtil. setContentView(this, R.layout.activity_main) binding.lifecycleOwner = this binding.viewmodel = viewModel }

Slide 26

Slide 26 text

Enable in grade file android { dataBinding { enabled true } }

Slide 27

Slide 27 text

In ViewBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) var binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding.root) viewModel.likes.observe(this, Observer { binding.count.text = "${it}" }) binding.like.setOnClickListener { viewModel.onLike() } }

Slide 28

Slide 28 text

Enable in grade file android { viewBinding { enabled = true } }

Slide 29

Slide 29 text

Thank you .