Android Programming The Big Nerd Ranch Guide by Bill Phillips, Chris Stewart, Kristin Marsicano (z-lib.org)

(gtxtreme123) #1

Chapter 20  Data Binding and MVVM


And then pass in BeatBox’s sounds in onCreateView(...).


Listing 20.19  Passing in Sounds to adapter (BeatBoxFragment.java)


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
FragmentBeatBoxBinding binding = DataBindingUtil
.inflate(inflater, R.layout.fragment_beat_box, container, false);


binding.recyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 3));
binding.recyclerView.setAdapter(new SoundAdapter());
binding.recyclerView.setAdapter(new SoundAdapter(mBeatBox.getSounds()));


return binding.getRoot();
}


With that, you should see a grid of buttons when you run BeatBox (Figure 20.6).


Figure 20.6  Empty buttons


To populate the buttons with titles, you will use some additional tools from your new data binding
utility belt.

Free download pdf