Example usage for android.view ViewGroup removeViews

List of usage examples for android.view ViewGroup removeViews

Introduction

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

Prototype

public void removeViews(int start, int count) 

Source Link

Document

Removes the specified range of views from the group.

Usage

From source file:dev.drsoran.moloko.util.UIUtils.java

public final static void inflateTags(Context context, ViewGroup container, Collection<String> tags,
        Bundle configuration) {/*from w w w .ja va 2  s. c  om*/
    if (configuration == null) {
        configuration = Bundle.EMPTY;
    }

    final int tagPos = getTaggedViewPos(container, "tag_name");

    if (tagPos != -1) {
        container.removeViews(tagPos, container.getChildCount() - tagPos);
    }

    // inflate the stub and add tags
    if (tags.size() > 0 && !configuration.containsKey(REMOVE_ALL_TAGS)) {
        try {
            final String[] tagsToRemove = configuration.getStringArray(REMOVE_TAGS_EQUALS);

            for (String tagText : tags) {
                boolean remove = false;

                if (tagsToRemove != null) {
                    for (int i = 0; i < tagsToRemove.length && !remove; i++) {
                        remove = tagsToRemove[i].equalsIgnoreCase(tagText);
                    }
                }

                if (!remove) {
                    final TextView tagView = (TextView) View.inflate(context, R.layout.tag_button, null);
                    tagView.setText(tagText);
                    container.addView(tagView);
                }
            }
        } catch (Throwable e) {
            throw new InflateException(e);
        }
    }

    if (container.getChildCount() > 0)
        container.setVisibility(View.VISIBLE);
    else
        container.setVisibility(View.GONE);
}

From source file:com.goliathonline.android.kegbot.ui.DrinkDetailFragment.java

private void updateLinksTab(Cursor cursor) {
    ViewGroup container = (ViewGroup) mRootView.findViewById(R.id.links_container);

    // Remove all views but the 'empty' view
    int childCount = container.getChildCount();
    if (childCount > 1) {
        container.removeViews(1, childCount - 1);
    }/*w  w  w.  j a  v a2  s  .c o  m*/

    LayoutInflater inflater = getLayoutInflater(null);

    boolean hasLinks = false;

    container.findViewById(R.id.empty_links).setVisibility(hasLinks ? View.GONE : View.VISIBLE);
}

From source file:com.google.android.apps.iosched.ui.SessionDetailFragment.java

private void updateLinksTab(Cursor cursor) {
    ViewGroup container = (ViewGroup) mRootView.findViewById(R.id.links_container);

    // Remove all views but the 'empty' view
    int childCount = container.getChildCount();
    if (childCount > 1) {
        container.removeViews(1, childCount - 1);
    }//from ww  w .j a v a 2  s .  c  om

    LayoutInflater inflater = getLayoutInflater(null);

    boolean hasLinks = false;
    for (int i = 0; i < SessionsQuery.LINKS_INDICES.length; i++) {
        final String url = cursor.getString(SessionsQuery.LINKS_INDICES[i]);
        if (!TextUtils.isEmpty(url)) {
            hasLinks = true;
            ViewGroup linkContainer = (ViewGroup) inflater.inflate(R.layout.list_item_session_link, container,
                    false);
            ((TextView) linkContainer.findViewById(R.id.link_text)).setText(SessionsQuery.LINKS_TITLES[i]);
            final int linkTitleIndex = i;
            linkContainer.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    fireLinkEvent(SessionsQuery.LINKS_TITLES[linkTitleIndex]);
                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
                    startActivity(intent);

                }
            });

            container.addView(linkContainer);

            // Create separator
            View separatorView = new ImageView(getActivity());
            separatorView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT));
            separatorView.setBackgroundResource(android.R.drawable.divider_horizontal_bright);
            container.addView(separatorView);
        }
    }

    container.findViewById(R.id.empty_links).setVisibility(hasLinks ? View.GONE : View.VISIBLE);
}

From source file:com.tomeokin.lspush.biz.home.CollectionListAdapter.java

private void setExplorers(ViewGroup container, @Nullable List<User> explorers) {
    final Context context = container.getContext();
    // // TODO: 2016/10/8 performance improve
    //container.removeAllViews();
    //for (User explorer : explorers) {
    //    final ImageView avatar =
    //        (ImageView) LayoutInflater.from(context).inflate(R.layout.layout_item_explorer, container, false);
    //    ImageLoader.loadAvatar(context, avatar, explorer.getImage());
    //    container.addView(avatar);
    //}/*from ww w.  ja  v a2  s  .  c  o  m*/

    final int count = container.getChildCount();
    int targetCount = explorers == null ? 0 : explorers.size();
    targetCount = targetCount >= 5 ? 5 : targetCount;
    final LayoutInflater inflater = LayoutInflater.from(context);
    if (count > targetCount) {
        container.removeViews(targetCount, count - targetCount);
    }
    ImageView avatar;
    for (int i = 0; i < targetCount; i++) {
        if (i > count - 1) { // no cache
            avatar = (ImageView) inflater.inflate(R.layout.layout_item_explorer, container, false);
        } else {
            avatar = (ImageView) container.getChildAt(i);
        }
        ImageLoader.loadAvatar(context, avatar, explorers.get(i).getImage());
        if (avatar.getParent() == null) {
            container.addView(avatar);
        }
        avatar.setTag(R.id.avatar_tag_uid, explorers.get(i).getUid());
        avatar.setOnClickListener(mExplorerListener);
    }
}

From source file:com.taobao.weex.WXSDKInstance.java

private void destroyView(View rootView) {
    try {//from w  ww  .  ja v a 2s  . c  om
        if (rootView instanceof ViewGroup) {
            ViewGroup cViewGroup = ((ViewGroup) rootView);
            for (int index = 0; index < cViewGroup.getChildCount(); index++) {
                destroyView(cViewGroup.getChildAt(index));
            }

            cViewGroup.removeViews(0, ((ViewGroup) rootView).getChildCount());
            // Ensure that the viewgroup's status to be normal
            WXReflectionUtils.setValue(rootView, "mChildrenCount", 0);

        }
        if (rootView instanceof Destroyable) {
            ((Destroyable) rootView).destroy();
        }
    } catch (Exception e) {
        WXLogUtils.e("WXSDKInstance destroyView Exception: ", e);
    }
}