Android Programming The Big Nerd Ranch Guide, 3rd Edition
Creating BeatBox 377 Open the newly renamed fragment_beat_box.xml. Delete the existing contents of the file. Then fill it up lik ...
Chapter 20 Data Binding and MVVM 378 Simple data binding The next job is to inflate fragment_beat_box.xml and hook up its Recyc ...
Simple data binding 379 So your FragmentBeatBoxBinding class has two references: getRoot(), which refers to the entire layout, a ...
Chapter 20 Data Binding and MVVM 380 With your binding created, you can now get at your RecyclerView and configure it. Listing ...
Simple data binding 381 Next, create a SoundHolder wired up to list_item_sound.xml. Listing 20.9 Creating SoundHolder (BeatBoxF ...
Chapter 20 Data Binding and MVVM 382 Now wire up SoundAdapter in onCreateView(...). Listing 20.11 Wiring up SoundAdapter (Beat ...
Importing Assets 383 Figure 20.3 Creating the assets folder Click Finish to create your assets folder. Next, right-click on ass ...
Chapter 20 Data Binding and MVVM 384 So where can you find the sounds? You will be using a Creative Commons-licensed sound set ...
Getting At Assets 385 Assets are accessed using the AssetManager class. You can get an AssetManager from any Context. Since Beat ...
Chapter 20 Data Binding and MVVM 386 To verify that this is working correctly, create an instance of BeatBox in BeatBoxFragment ...
Wiring Up Assets for Use 387 In the constructor, you do a little work to make a presentable name for your sound. First, you spli ...
Chapter 20 Data Binding and MVVM 388 And then pass in BeatBox’s sounds in onCreateView(...). Listing 20.19 Passing in Sounds t ...
Binding to Data 389 Binding to Data With data binding, you can declare data objects within your layout file: <layout xmlns:an ...
Chapter 20 Data Binding and MVVM 390 However, this causes some architectural issues. To see why, look at it from an MVC perspec ...
Creating a ViewModel 391 Creating a ViewModel Let’s create your view model. Create a new class called SoundViewModel and give it ...
Chapter 20 Data Binding and MVVM 392 Binding to a ViewModel Now to integrate the view model into your layout file. The first st ...
Binding to a ViewModel 393 Inside your constructor, you construct and attach your view model. Then, in your bind method, you upd ...
Chapter 20 Data Binding and MVVM 394 Observable data All may appear to be well, but darkness lies hidden in your code. You can ...
Observable data 395 Three steps are required with this method: Subclass BaseObservable in your view model. Annotate your view m ...
Chapter 20 Data Binding and MVVM 396 Figure 20.13 All done Accessing Assets You have finished all the work for this chapter. Y ...
«
16
17
18
19
20
21
22
23
24
25
»
Free download pdf