Example usage for android.view ViewStub setOnInflateListener

List of usage examples for android.view ViewStub setOnInflateListener

Introduction

In this page you can find the example usage for android.view ViewStub setOnInflateListener.

Prototype

public void setOnInflateListener(OnInflateListener inflateListener) 

Source Link

Document

Specifies the inflate listener to be notified after this ViewStub successfully inflated its layout resource.

Usage

From source file:com.google.samples.apps.ourstreets.fragment.GalleryFragment.java

private void setupAndInflate(ViewStub failedStub) {
    failedStub.setOnInflateListener(new ViewStub.OnInflateListener() {
        @Override/*from  w  w  w.  ja va2 s  .  co m*/
        public void onInflate(ViewStub stub, final View inflated) {
            inflated.findViewById(R.id.try_again).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    new GalleryPresenter(GalleryFragment.this).getData();
                    mEmptyView.setVisibility(View.VISIBLE);
                    inflated.setVisibility(View.GONE);
                }
            });
        }
    });
    failedStub.inflate();
}

From source file:com.android.settings.PreviewPagerAdapter.java

public PreviewPagerAdapter(Context context, boolean isLayoutRtl, int[] previewSampleResIds,
        Configuration[] configurations) {
    mIsLayoutRtl = isLayoutRtl;// w w  w .j  a v a  2s  .c o m
    mPreviewFrames = new FrameLayout[previewSampleResIds.length];
    mViewStubInflated = new boolean[previewSampleResIds.length][configurations.length];

    for (int i = 0; i < previewSampleResIds.length; ++i) {
        int p = mIsLayoutRtl ? previewSampleResIds.length - 1 - i : i;
        mPreviewFrames[p] = new FrameLayout(context);
        mPreviewFrames[p].setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.MATCH_PARENT));

        for (int j = 0; j < configurations.length; ++j) {
            // Create a new configuration for the specified value. It won't
            // have any theme set, so manually apply the current theme.
            final Context configContext = context.createConfigurationContext(configurations[j]);
            configContext.setTheme(context.getThemeResId());

            final LayoutInflater configInflater = LayoutInflater.from(configContext);
            final ViewStub sampleViewStub = new ViewStub(configContext);
            sampleViewStub.setLayoutResource(previewSampleResIds[i]);
            final int fi = i, fj = j;
            sampleViewStub.setOnInflateListener(new OnInflateListener() {
                @Override
                public void onInflate(ViewStub stub, View inflated) {
                    inflated.setVisibility(stub.getVisibility());
                    mViewStubInflated[fi][fj] = true;
                }
            });

            mPreviewFrames[p].addView(sampleViewStub);
        }
    }
}