0

I can't figure out how to connect a listener to a separate class called by an activity.

I have My activity, which loads a tabbed view of Fragments. Each Fragment loads its own recycler view

Activity ---> ViewPager(Tabs) ----> Fragments ---> RecyclerView//(This is where I want the listener)
|
|
Background Handler for calling a web server periodically //(I want this to call the listener).

In my mind the RecyclerView and the Handler are different.

I only know how to implement a listener in the class that creates the caller.

How can I add a listener to a class that is not connected to the caller?

Twisha Kotecha
  • 1,082
  • 1
  • 4
  • 18
silversunhunter
  • 1,219
  • 2
  • 12
  • 32

1 Answers1

0

the question was a little confusing but i hope this solution help in kotlin:

  1. define a kotlin callback in recyclerView adapter and call it for example on click

  2. define a kotlin callback in viewPager and implement in in Activity

  3. implement RVAdapter call back in viewpager fragment create method which job is to invoke activity callback

  4. in activity when you impl view pager adapter callback you can call your handler

if you'r code is in java you can use abstract classes.

Amir Abbas
  • 305
  • 3
  • 8