Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b6af5331 authored by Mihai Preda's avatar Mihai Preda
Browse files

Allow ViewStub to be used in AdapterView.setEmptyView() (bug 1803058)

parent 84c9097d
Loading
Loading
Loading
Loading
+15 −3
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ import android.util.AttributeSet;

import com.android.internal.R;

import java.lang.ref.WeakReference;

/**
 * A ViewStub is an invisible, zero-sized View that can be used to lazily inflate
 * layout resources at runtime.
@@ -68,6 +70,8 @@ public final class ViewStub extends View {
    private int mLayoutResource = 0;
    private int mInflatedId;

    private WeakReference<View> mInflatedViewRef;

    private OnInflateListener mInflateListener;

    public ViewStub(Context context) {
@@ -196,9 +200,15 @@ public final class ViewStub extends View {
     */
    @Override
    public void setVisibility(int visibility) {
        if (mInflatedViewRef != null) {
            View view = mInflatedViewRef.get();
            if (view != null) {
                view.setVisibility(visibility);
            } else {
                throw new IllegalStateException("setVisibility called on un-referenced view");
            }
        } else if (visibility == VISIBLE || visibility == INVISIBLE) {
            super.setVisibility(visibility);

        if (visibility == VISIBLE || visibility == INVISIBLE) {
            inflate();
        }
    }
@@ -234,6 +244,8 @@ public final class ViewStub extends View {
                    parent.addView(view, index);
                }

                mInflatedViewRef = new WeakReference(view);

                if (mInflateListener != null) {
                    mInflateListener.onInflate(this, view);
                }
+1 −1
Original line number Diff line number Diff line
@@ -162,7 +162,7 @@ public abstract class AdapterView<T extends Adapter> extends ViewGroup {
    /**
     * View to show if there are no items to show.
     */
    View mEmptyView;
    private View mEmptyView;

    /**
     * The number of items in the current adapter.