34,333
edits
Changes
→Modifying the Fragment
</pre>
In the previous chapter entitled TBD, the onClick property of the Button widget was use to designate the method to be called when the button is clicked by the user. Unfortunately, this property is only able to call methods on an Activity and cannot be used to call a method in a Fragment. To get around this limitation, we will need to add some code to the Fragment class to set up an onClick listener on the button. The code to do this can be added to the onActivityCreated() method as follows:
<pre>
</pre>
With the listener added, any code placed within the onClick() method will be called whenever the button is clicked by the user.
== Accessing the ViewModel Data ==