Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Thanks to mihail's hint (thanks for that :)) )with the <em>hidden API</em>, I've found a solution to get a listener back after assignment:</p> <p>The <code>android.view.View</code> class has a nested class <code>static class ListenerInfo</code> that stores all listeners on a View (API 14+). In older versions the listeners are private fields in the <code>android.view.View</code>.</p> <p>The field can be accessed with reflection. In my case (API 14+), </p> <pre><code>// get the nested class `android.view.View$ListenerInfo` Field listenerInfoField = null; listenerInfoField = Class.forName("android.view.View").getDeclaredField("mListenerInfo"); if (listenerInfoField != null) { listenerInfoField.setAccessible(true); } Object myLiObject = null; myLiObject = listenerInfoField.get(myViewObj); // get the field mOnClickListener, that holds the listener and cast it to a listener Field listenerField = null; listenerField = Class.forName("android.view.View$ListenerInfo").getDeclaredField("mOnClickListener") if (listenerField != null &amp;&amp; myLiObject != null) { View.OnClickListener myListener = (View.OnClickListener) listenerField.get(myLiObject); } </code></pre> <p>After that code (I missed a lot of try-catch-blocks), the myListener object holds the instance of the onClickListener, that has been anonymously declared to the view before. It also works with any other listener, just replace the "mOnClickListener parameter" with the one you need in the reflection and cast it correctly.</p> <p>Note that code changes in upcoming versions can make that not working anymore.</p> <p>Found the final tutorial here: <a href="http://andwise.net/?p=161" rel="noreferrer">http://andwise.net/?p=161</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload