Java tutorial
//package com.java2s; import java.lang.ref.WeakReference; import java.lang.reflect.Field; import android.os.Build; import android.view.ViewTreeObserver.OnScrollChangedListener; import android.widget.PopupWindow; public class Main { public final static void fixPopupWindow(final PopupWindow window) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) { try { final Field mAnchorField = PopupWindow.class.getDeclaredField("mAnchor"); mAnchorField.setAccessible(true); Field mOnScrollChangedListenerField = PopupWindow.class .getDeclaredField("mOnScrollChangedListener"); mOnScrollChangedListenerField.setAccessible(true); final OnScrollChangedListener mOnScrollChangedListener = (OnScrollChangedListener) mOnScrollChangedListenerField .get(window); OnScrollChangedListener newListener = new OnScrollChangedListener() { public void onScrollChanged() { try { WeakReference<?> mAnchor = WeakReference.class.cast(mAnchorField.get(window)); Object anchor = mAnchor != null ? mAnchor.get() : null; if (anchor == null) { return; } else { mOnScrollChangedListener.onScrollChanged(); } } catch (Exception e) { e.printStackTrace(); } } }; mOnScrollChangedListenerField.set(window, newListener); } catch (Exception e) { } } } }