noob help with making object A available to class B by passing them in as an argument to a class B’s constructor

i have three kotlin files in android and one is the main activity and the other two are recyclerlist adapters. and so, i instantiated my recycler class 2 in main activity, then pass it in as a parameter in the constructor of the recyclerList adapter class 1. basically allowing adapter 1 to have access to adapter 2 so i can call adapter 2’s notifyDataSetChange() in adapter 1.

i then created the variable for adapter 2 in the adapter 1’s class declaration (i think thats what its called, like class rvAdap1(private var blah blah):blah blah) and i got no error. i then called notifyDataSetChanged in adapter 1 by running it, but nothing happened. the function didn’t run but i also got no error that notifyDataSetChanged was undefined in adapter 1.

i can share the code but from what i explained, is there something i clearly did incorrectly?

for now, i fixed the problem alternatively, by undoing everything above and simply instantiating recycler class 1 in main activity above the class declaration for main activity. so like outside of it. that way i could import recycler class 1 into any classes/files i want. but i dont think this is good practice?

submitted by /u/lasagna_lee
[link] [comments]