ViewGroup indexOfChild - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for ViewGroup indexOfChild method.

This code example shows how to use the following methods:invalidate, addView, indexOfChild, removeView
			 
		} else { 
			 
			// TODO verify that parent is indeed a ViewGroup 
			ViewGroup group = (ViewGroup) parent; 
			int index = group.indexOfChild(target);
			 
			group.removeView(target);
			group.addView(container, index, lp);
			 
			container.addView(target);
	 
			this.setVisibility(View.GONE);
			container.addView(this);
			 
			group.invalidate();
			 
		} 
		 
	} 
	 
8
CodeRank
This code example shows how to use the following methods:addView, indexOfChild
            // the container for the progress view must behave identically to this view during 
            // layouting, otherwise e.g. relative positioning via IDs will break 
            progressViewContainer.setLayoutParams(getLayoutParams());
 
            ViewGroup parent = (ViewGroup) getParent();
            int index = parent.indexOfChild(this);
            parent.addView(progressViewContainer, index + 1);
        } 
 
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    } 
 
    /** 
     * Use this method to trigger the image download if you had previously set autoLoad to false. 
     */ 
    public void loadImage() { 
        if (state != STATE_LOADING) {
            if (imageUrl == null) {
                throw new IllegalStateException(
                        "image URL is null; did you forget to set it for this view?"); 
7
CodeRank
This code example shows how to use the following methods:invalidate, addView, indexOfChild, removeView
			 
		} else { 
			 
			// TODO verify that parent is indeed a ViewGroup 
			ViewGroup group = (ViewGroup) parent; 
			int index = group.indexOfChild(target);
			 
			group.removeView(target);
			group.addView(container, index, lp);
			 
			container.addView(target);
	 
			this.setVisibility(View.GONE);
			container.addView(this);
			 
			group.invalidate();
			 
		} 
		 
	} 
	 
8
CodeRank
This code example shows how to use the following methods:addView, indexOfChild, removeView
	} 
	 
	public void toggleProgress(View view, boolean active)
	{ 
		RelativeLayout container = (RelativeLayout) view;
		int childIndex = container.indexOfChild(_hostProgressBar);
		 
		if(active && childIndex == -1)
		{ 
			_hostProgressBar = new ProgressBar(getContext());
			_hostProgressBar.setIndeterminate(true);
			LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, 
					LayoutParams.WRAP_CONTENT);
			params.alignWithParent = true;
			params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
			params.addRule(RelativeLayout.CENTER_VERTICAL);
			container.addView(_hostProgressBar, params);
		} 
		else if(!active && childIndex > -1)
		{ 

6
CodeRank
This code example shows how to use the following methods:indexOfChild, removeView
        mContentView.addView(tab);
        tab.setActivated(false);
    } 
 
    void removeTab(View tab) {
        int ix = mContentView.indexOfChild(tab);
        if (ix == mSelected) {
            mSelected = -1;
        } else if (ix < mSelected) {
            mSelected--;
        } 
        mContentView.removeView(tab);
    } 
 
    private void ensureChildVisible(View child) {
        if (child != null) {
            int childl = child.getLeft();
            int childr = childl + child.getWidth();
            int viewl = getScrollX();
            int viewr = viewl + getWidth();
6
CodeRank
This code example shows how to use the following methods:addView, indexOfChild, removeView
        if (mContentContainer instanceof ViewGroup) {
            ViewGroup contentContainer = (ViewGroup) mContentContainer;
            if (mContentView == null) {
                contentContainer.addView(view);
            } else { 
                int index = contentContainer.indexOfChild(mContentView);
                // replace content view 
                contentContainer.removeView(mContentView);
                contentContainer.addView(view, index);
            } 
            mContentView = view;
        } else { 
            throw new IllegalStateException("Can't be used with a custom content view");
        } 
    } 
 
    /** 
     * The default content for a ProgressFragment has a TextView that can be shown when 
     * the content is empty {@link #setContentEmpty(boolean)}. 
     * If you would like to have it shown, call this method to supply the text it should use. 
7
CodeRank
This code example shows how to use the following methods:addView, indexOfChild, removeView
        if (mContentContainer instanceof ViewGroup) {
            ViewGroup contentContainer = (ViewGroup) mContentContainer;
            if (mContentView == null) {
                contentContainer.addView(view);
            } else { 
                int index = contentContainer.indexOfChild(mContentView);
                // replace content view 
                contentContainer.removeView(mContentView);
                contentContainer.addView(view, index);
            } 
            mContentView = view;
        } else { 
            throw new IllegalStateException("Can't be used with a custom content view");
        } 
    } 
 
    /** 
     * The default content for a ProgressFragment has a TextView that can be shown when 
     * the content is empty {@link #setContentEmpty(boolean)}. 
     * If you would like to have it shown, call this method to supply the text it should use. 
7
CodeRank
This code example shows how to use the following methods:addView, indexOfChild, removeView
        } 
 
        if (mContentView == null) {
            mContentContainer.addView(view);
        } else { 
            int index = mContentContainer.indexOfChild(mContentView);
            // replace content view 
            mContentContainer.removeView(mContentView);
            mContentContainer.addView(view, index, new LayoutParams(LayoutParams.MATCH_PARENT,
                    LayoutParams.MATCH_PARENT));
        } 
        mContentView = view;
    } 
 
    /** 
     * Set the content content from a layout resource. 
     * 
     * @param layoutResId Resource ID to be inflated. 
     * 
     * @see #setContentView(android.view.View) 
6
CodeRank
This code example shows how to use the following methods:indexOfChild, removeViews
 
		return button;
	} 
 
	public boolean removeButton(final ImageButton button) {
		final int index = view.indexOfChild(button);
		if (index == -1)
			return false; 
 
		view.removeViews(index - 2, 3);
		return true; 
	} 
} 
6
CodeRank
This code example shows how to use the following methods:addView, indexOfChild
    } 
 
    private static int insertView( 
            ViewGroup container, View newView, View existingView, boolean after) {
        // See if the view has already been added. 
        int index = container.indexOfChild(newView);
        if (index >= 0) return index;
 
        // Find the location of the existing view. 
        index = container.indexOfChild(existingView);
        if (index < 0) return -1;
 
        // Add the view. 
        if (after) index++;
        container.addView(newView, index);
        return index;
    } 
 
    /** 
     * Generates a scaled screenshot of the given view.  The maximum size of the screenshot is 
6
CodeRank

Related ViewGroup indexOfChild Questions & Answers:

indexOfChild Method Overview
Returns the position in the group of the specified child view.
See Code Examples for other Android ViewGroup Methods: