Example usage for android.view ViewGroup removeAllViews

List of usage examples for android.view ViewGroup removeAllViews

Introduction

In this page you can find the example usage for android.view ViewGroup removeAllViews.

Prototype

public void removeAllViews() 

Source Link

Document

Call this method to remove all child views from the ViewGroup.

Usage

From source file:com.hichinaschool.flashcards.anki.StudyOptionsFragment.java

void setFragmentContentView(View newView) {
    ViewGroup parent = (ViewGroup) this.getView();
    parent.removeAllViews();
    parent.addView(newView);
}

From source file:com.saarang.samples.apps.iosched.ui.SessionDetailActivity.java

private void buildLinksSection(Cursor cursor) {
    // Compile list of links (I/O live link, submit feedback, and normal links)
    ViewGroup linkContainer = (ViewGroup) findViewById(com.saarang.samples.apps.iosched.R.id.links_container);
    linkContainer.removeAllViews();

    // Build links section
    // the Object can be either a string URL or an Intent
    List<Pair<Integer, Object>> links = new ArrayList<Pair<Integer, Object>>();

    long currentTimeMillis = UIUtils.getCurrentTime(this);
    if (mHasLivestream && currentTimeMillis > mSessionStart && currentTimeMillis <= mSessionEnd) {
        links.add(new Pair<Integer, Object>(com.saarang.samples.apps.iosched.R.string.session_link_livestream,
                getWatchLiveIntent(this)));
    }// w w  w. ja  v a2  s .  c o  m

    // Add session feedback link, if appropriate
    if (!mAlreadyGaveFeedback && currentTimeMillis > mSessionEnd - Config.FEEDBACK_MILLIS_BEFORE_SESSION_END) {
        links.add(new Pair<Integer, Object>(
                com.saarang.samples.apps.iosched.R.string.session_feedback_submitlink, getFeedbackIntent()));
    }

    for (int i = 0; i < SessionsQuery.LINKS_INDICES.length; i++) {
        final String linkUrl = cursor.getString(SessionsQuery.LINKS_INDICES[i]);
        if (TextUtils.isEmpty(linkUrl)) {
            continue;
        }

        links.add(new Pair<Integer, Object>(SessionsQuery.LINKS_TITLES[i],
                new Intent(Intent.ACTION_VIEW, Uri.parse(linkUrl))
                        .addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET)));
    }

    // Render links
    if (links.size() > 0) {
        LayoutInflater inflater = LayoutInflater.from(this);
        int columns = getResources().getInteger(com.saarang.samples.apps.iosched.R.integer.links_columns);

        LinearLayout currentLinkRowView = null;
        for (int i = 0; i < links.size(); i++) {
            final Pair<Integer, Object> link = links.get(i);

            // Create link view
            TextView linkView = (TextView) inflater.inflate(
                    com.saarang.samples.apps.iosched.R.layout.list_item_session_link, linkContainer, false);
            if (link.first == com.saarang.samples.apps.iosched.R.string.session_feedback_submitlink) {
                mSubmitFeedbackView = linkView;
            }
            linkView.setText(getString(link.first));
            linkView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    fireLinkEvent(link.first);
                    Intent intent = null;
                    if (link.second instanceof Intent) {
                        intent = (Intent) link.second;
                    } else if (link.second instanceof String) {
                        intent = new Intent(Intent.ACTION_VIEW, Uri.parse((String) link.second))
                                .addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
                    }
                    try {
                        startActivity(intent);
                    } catch (ActivityNotFoundException ignored) {
                    }
                }
            });

            // Place it inside a container
            if (columns == 1) {
                linkContainer.addView(linkView);
            } else {
                // create a new link row
                if (i % columns == 0) {
                    currentLinkRowView = (LinearLayout) inflater.inflate(
                            com.saarang.samples.apps.iosched.R.layout.include_link_row, linkContainer, false);
                    currentLinkRowView.setWeightSum(columns);
                    linkContainer.addView(currentLinkRowView);
                }

                ((LinearLayout.LayoutParams) linkView.getLayoutParams()).width = 0;
                ((LinearLayout.LayoutParams) linkView.getLayoutParams()).weight = 1;
                currentLinkRowView.addView(linkView);
            }
        }

        findViewById(com.saarang.samples.apps.iosched.R.id.session_links_header).setVisibility(View.VISIBLE);
        findViewById(com.saarang.samples.apps.iosched.R.id.links_container).setVisibility(View.VISIBLE);

    } else {
        findViewById(com.saarang.samples.apps.iosched.R.id.session_links_header).setVisibility(View.GONE);
        findViewById(com.saarang.samples.apps.iosched.R.id.links_container).setVisibility(View.GONE);
    }

}

From source file:org.appcelerator.titanium.view.TiUIView.java

public void release() {
    Log.d(TAG, "Releasing: " + this, Log.DEBUG_MODE);
    View nv = getNativeView();/*  w  ww  . j a  v a2  s  .co m*/
    if (nv != null) {
        if (nv instanceof ViewGroup) {
            ViewGroup vg = (ViewGroup) nv;
            Log.d(TAG, "Group has: " + vg.getChildCount(), Log.DEBUG_MODE);
            if (!(vg instanceof AdapterView<?>)) {
                vg.removeAllViews();
            }
        }
        Drawable d = nv.getBackground();
        if (d != null) {
            nv.setBackgroundDrawable(null);
            d.setCallback(null);
            if (d instanceof TiBackgroundDrawable) {
                ((TiBackgroundDrawable) d).releaseDelegate();
            }
            d = null;
        }
        nativeView = null;
        borderView = null;
        if (proxy != null) {
            proxy.setModelListener(null);
        }
    }
}

From source file:de.azapps.mirakel.main_activity.MainActivity.java

/**
 * Initialize the ViewPager and setup the rest of the layout
 *///  w w  w. j  a v  a2 s  . co  m
private void setupLayout() {
    if (this.currentList == null) {
        setCurrentList(SpecialList.firstSpecialSafe());
    }
    // clear tabletfragments
    final ViewGroup all = (ViewGroup) this.findViewById(R.id.multi_pane_box);
    if ((all != null) && MirakelCommonPreferences.isTablet()) {
        for (int i = 0; i < all.getChildCount(); i++) {
            final ViewGroup group = (ViewGroup) all.getChildAt(i);
            group.removeAllViews();
            Log.d(TAG, "Clear view " + i);
        }
    }
    // Initialize ViewPager
    /*
     * TODO We need the try catch because it throws sometimes a
     * runtimeexception when adding fragments.
     */
    try {
        initViewPager();
    } catch (final Exception e) {
        Log.wtf(TAG, "initViewPager throwed an exception", e);
    }
    initNavDrawer();
    this.startIntent = getIntent();
    handleIntent(this.startIntent);
}

From source file:com.malin.rxjava.activity.MainActivity.java

/**
 * ???Activity onDestoryviewrootview/*from   ww w.  j av  a  2  s .c o  m*/
 * ?view?DrawingCache??
 * Activity???????
 *
 * @param view:the root view of the layout
 * @description Unbind the rootView
 * @author malin.myemail@gmail.com
 * @link http://stackoverflow.com/questions/9461364/exception-in-unbinddrawables
 * http://mp.weixin.qq.com/s?__biz=MzAwNDY1ODY2OQ==&mid=400656149&idx=1&sn=122b4f4965fafebf78ec0b4fce2ef62a&3rd=MzA3MDU4NTYzMw==&scene=6#rd
 * @since 2015.12.16
 */
private void unBindDrawables(View view) {
    if (view != null) {
        try {
            Drawable drawable = view.getBackground();
            if (drawable != null) {
                drawable.setCallback(null);
            } else {
            }
            if (view instanceof ViewGroup && !(view instanceof AdapterView)) {
                ViewGroup viewGroup = (ViewGroup) view;
                int viewGroupChildCount = viewGroup.getChildCount();
                for (int j = 0; j < viewGroupChildCount; j++) {
                    unBindDrawables(viewGroup.getChildAt(j));
                }
                viewGroup.removeAllViews();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

From source file:android.support.v7.app.AppCompatDelegateImplV7.java

@Override
public void setContentView(View v) {
    ensureSubDecor();/*w ww  .ja  v a2s  . co m*/
    ViewGroup contentParent = (ViewGroup) mSubDecor.findViewById(android.R.id.content);
    contentParent.removeAllViews();
    contentParent.addView(v);
    mOriginalWindowCallback.onContentChanged();
}

From source file:android.support.v7.app.AppCompatDelegateImplV7.java

@Override
public void setContentView(int resId) {
    ensureSubDecor();/*  www.j  a  va 2  s .co m*/
    ViewGroup contentParent = (ViewGroup) mSubDecor.findViewById(android.R.id.content);
    contentParent.removeAllViews();
    LayoutInflater.from(mContext).inflate(resId, contentParent);
    mOriginalWindowCallback.onContentChanged();
}

From source file:android.support.v7.app.AppCompatDelegateImplV7.java

@Override
public void setContentView(View v, ViewGroup.LayoutParams lp) {
    ensureSubDecor();/*w  w w  .  j a  v a 2s.  co m*/
    ViewGroup contentParent = (ViewGroup) mSubDecor.findViewById(android.R.id.content);
    contentParent.removeAllViews();
    contentParent.addView(v, lp);
    mOriginalWindowCallback.onContentChanged();
}

From source file:com.dk.view.FolderDrawerLayout.java

private void revertView() {
    if (mLeftCache != null && mLeftCache.getParent() == null) {
        ViewGroup left = (ViewGroup) findDrawerWithGravity(Gravity.LEFT);
        left.removeAllViews();
        left.addView(mLeftCache);/*from  w  w  w. j  a  va2s  . c  om*/
    }
}

From source file:com.dk.view.FolderDrawerLayout.java

private void replaceView() {
    ViewGroup left = (ViewGroup) findDrawerWithGravity(Gravity.LEFT);
    mLeftCache = left.getChildAt(0);/*  w w  w .  j a v  a2 s  .c o m*/
    left.removeAllViews();
    mMeshImageView = new MeshImageView(getContext());
    mMeshImageView.setImageBitmap(mDrawingCache);

    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(-1, -1);
    left.addView(mMeshImageView, params);
    if (isDrawerOpen(Gravity.LEFT)) {
        mCoreCalc.setDirection(Direction.LEFT);
    } else {
        mCoreCalc.setDirection(Direction.RIGHT);
    }

    mMeshImageView.setMeshVerts(mCoreCalc.createOffsetVerts(1, mInitialMotionY));

    // mMeshImageView.getViewTreeObserver().addOnPreDrawListener(new
    // OnPreDrawListener() {
    //
    // @Override
    // public boolean onPreDraw() {
    //
    //
    // return false;
    // }
    // });
}