Fragment android beginner question | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 1

Fragment android beginner question

this is a code i found in a book.the code is trying to communicate between fragments with the help of the mainActivity. "this.listener = (WorkoutListListener) activity;" 1)why in the onAttach method we have to cast the interface to the activity? 2)why is it equals to this.listener(instance of WorkoutListListener) https://code.sololearn.com/cLhdwaVOm9vf/?ref=app

7th Dec 2017, 11:59 AM
oyl
1 Réponse
0
actually here it is used for getting the context of this class and used for initialization purpose so that it does not give null pointer exception
11th Dec 2017, 1:17 PM
Shivam Singh
Shivam Singh - avatar