dimanche 21 janvier 2018

How to register Callback of Interface using Relfection? Android

I have an interface:

package com.testing.server;

public interface OnViewFoundListener{
     void onViewFound(String msg);
}

And the Class that registers Listeners

   public class FindViewUtil {
               private static final List<OnViewFoundListener> 
       mOnViewFoundListeners = new ArrayList<>();

      public static void addViewListener(OnViewFoundListener onViewFoundListener) 
      {
        mOnViewFoundListeners.add(onViewFoundListener);
      }

     public static void notifyViewRendered() {
         mOnViewFoundListeners.get(0).onViewFound("Hello World");
     } 

    }

I want to be able to register using the addViewListener function and listen for OnViewFoundListener's onViewFound callbacks via Reflection. How can I achieve this goal ?





Aucun commentaire:

Enregistrer un commentaire