ViewGroup getChildCount - 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 getChildCount method.

This code example shows how to use the following methods:getVerticalFadingEdgeLength, getChildAt, getChildCount, getMaxScrollAmount, getCount
        mListUtil = new ListUtil(mListView, getInstrumentation());
    } 
 
    @MediumTest 
    public void testPreconditions() { 
        assertEquals("list item count", 5, mListView.getCount());
        assertEquals("list visible child count", 3, mListView.getChildCount());
        int firstTwoHeight = mListView.getChildAt(0).getHeight() + mListView.getChildAt(1).getHeight();
        assertTrue("first two items should fit within fading edge",
                firstTwoHeight <= mListView.getVerticalFadingEdgeLength());
        assertTrue("first two items should fit within list max scroll",
                firstTwoHeight <= mListView.getMaxScrollAmount());
    } 
 
    @MediumTest 
    public void testFadeTopTwoItemsOut() { 
        // put 2nd item selected 
        sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
        sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
 
7
CodeRank
This code example shows how to use the following methods:getChildAt, getChildCount, getListPaddingTop, getAdapter
                newLastChild.getId());
    } 
     
    @LargeTest 
    public void testShortScroll() { 
        View firstChild = mListView.getChildAt(0);
        if (firstChild.getTop() < this.mListView.getListPaddingTop()) {
            firstChild = mListView.getChildAt(1);
        } 
             
        View lastChild = mListView.getChildAt(mListView.getChildCount() - 1);
         
        int lastTop = lastChild.getTop();
         
        TouchUtils.dragViewBy(this, firstChild, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL,
                0, ViewConfiguration.getTouchSlop() + 1 + 10);
         
        View newLastChild = mListView.getChildAt(mListView.getChildCount() - 1);
         
        assertEquals("View scrolled to wrong position", lastTop, newLastChild.getTop() - 10);

8
CodeRank
This code example shows how to use the following methods:scrollToBottom, getHeight, getChildAt, getChildCount, getListPaddingBottom
                firstChild.getTop());
    } 
     
    @LargeTest 
    public void testPushUp() { 
        int originalCount = mListView.getChildCount();
         
        TouchUtils.scrollToBottom(this, mListView);
 
        // Nothing should be selected 
        assertEquals("Selection still available after touch", -1, 
                mListView.getSelectedItemPosition());
 
        View lastChild = mListView.getChildAt(mListView.getChildCount() - 1);
 
        assertEquals("List is not scrolled to the bottom", mListView.getAdapter().getCount() - 1,
                lastChild.getId());
 
        assertEquals("Last item is not touching the bottom edge",  
                mListView.getHeight() - mListView.getListPaddingBottom(), lastChild.getBottom());

7
CodeRank
This code example shows how to use the following methods:isInTouchMode, getChildAt, getChildCount, sleep, getFirstVisiblePosition
       int firstVisiblePosition = touchScroll(inst);
         
        inst.sendCharacterSync(KeyEvent.KEYCODE_BACK);
        inst.waitForIdleSync();
         
        assertTrue("List not in touch mode", mListView.isInTouchMode()); 
        assertTrue("List did not preserve scroll position", 
                firstVisiblePosition == mListView.getFirstVisiblePosition()); 
    } 
     
    /** 
     * Scroll the list using arrows, launch new activity, change to touch mode, hit back, make sure 
     * we're still scrolled. 
     */ 
    @LargeTest 
    public void testKeyScrollingToTouchMode() { 
        Instrumentation inst = getInstrumentation();
         
        int firstVisiblePosition = arrowScroll(inst);
         

7
CodeRank
This code example shows how to use the following methods:getChildAt, getChildCount, getListPaddingBottom, getMaxScrollAmount
    } 
 
    @MediumTest 
    public void testPreconditions() { 
        assertNotNull(mListView);
        assertEquals("should only be one visible child", 1, mListView.getChildCount());
        final int amountOffScreen = mListView.getChildAt(0).getBottom() - (mListView.getBottom() - mListView.getListPaddingBottom());
        assertTrue("must be more than max scroll off screen for this test to work",
                amountOffScreen > mListView.getMaxScrollAmount());
    } 
 
    @MediumTest 
    public void testScrollDownAcrossItem() { 
        final View view = mListView.getSelectedView();
        assertTrue(view.isSelected());
 
        assertEquals(mListView.getListPaddingTop(),
                view.getTop());
 
        assertTrue("view must be taller than screen for this test to be worth anything",
7
CodeRank
This code example shows how to use the following methods:addView, getChildAt, getChildCount, setOrientation
		 
		// check (expected) toast layout 
		if (rootView instanceof LinearLayout) {
			linearLayout = (LinearLayout) rootView;
			 
			if (linearLayout.getChildCount() == 1) {
				View child = linearLayout.getChildAt(0);
				 
				if (child instanceof TextView) {
					messageTextView = (TextView) child;
					 
					if (!(messageTextView.getLayoutParams() instanceof LinearLayout.LayoutParams)) {
						messageTextView = null;
					} 
				} 
			} 
		} 
		 
		// cancel modification because toast layout is not what we expected 
		if (linearLayout == null || messageTextView == null) {

7
CodeRank
This code example shows how to use the following methods:getVerticalFadingEdgeLength, getChildCount, getSelectedView, getAdapter
 
    @MediumTest 
    public void testPreconditions() { 
        assertNotNull(mListView);
        assertTrue("need item height less than fading edge length",
                mListView.getSelectedView().getHeight() < mListView.getVerticalFadingEdgeLength());
        assertTrue("need items off screen",
                mListView.getChildCount() < mListView.getAdapter().getCount());
    } 
 
    @LargeTest 
    public void testScrollToBottom() { 
        final int numItems = mListView.getAdapter().getCount();
        final int listBottom = mListView.getHeight() - mListView.getListPaddingBottom();
        for (int i = 0; i < numItems; i++) {
            assertEquals("wrong selection at position " + i,
                    i, mListView.getSelectedItemPosition());
            final int bottomFadingEdge = listBottom - mListView.getVerticalFadingEdgeLength();
            final View lastChild = mListView.getChildAt(mListView.getChildCount() - 1);
            final int lastVisiblePosition = lastChild.getId();
7
CodeRank
This code example shows how to use the following methods:getContext, getChildAt, getChildCount, getCount, getLastVisiblePosition
	@Override 
	public void onScrollStateChanged(AbsListView view, int scrollState) {
		switch (scrollState) {
        case OnScrollListener.SCROLL_STATE_IDLE:
		    //Log.v(TAG, "已经停止:SCROLL_STATE_IDLE" + "-->" + view.getCount()); 
		    Context context = view.getContext();
		    YiBoApplication yibo = (YiBoApplication) context.getApplicationContext();
		    if (view.getLastVisiblePosition() == view.getCount() - 1
		    	&& yibo.isAutoLoadMore()) {
		    	view.getChildAt(view.getChildCount() - 1).performClick();
		    } 
		    break; 
        case OnScrollListener.SCROLL_STATE_FLING:
		    //Log.v(TAG, "开始滚动:SCROLL_STATE_FLING"); 
		    break; 
		case OnScrollListener.SCROLL_STATE_TOUCH_SCROLL:
		   //Log.v(TAG, "正在滚动:SCROLL_STATE_TOUCH_SCROLL"); 
		   break; 
	    } 
	} 
7
CodeRank
This code example shows how to use the following methods:getTop, getChildAt, getChildCount
        assertEquals("Wrong view in first position", 0, newFirstChild.getId());
    } 
     
    @LargeTest 
    public void testLongScroll() { 
        View lastChild = mListView.getChildAt(mListView.getChildCount() - 1);
         
        int lastTop = lastChild.getTop();
         
        int distance = TouchUtils.dragViewToY(this, lastChild, 
                Gravity.TOP | Gravity.LEFT, mListView.getTop());
         
        assertEquals("View scrolled to wrong position", 
                lastTop - (distance - ViewConfiguration.getTouchSlop() - 1), lastChild.getTop());
    }  
 
} 
7
CodeRank
This code example shows how to use the following methods:setEnabled, setVisibility, addView, getChildCount, removeAllViews
 
    public void setEnabled(boolean enabled) {
        super.setEnabled(enabled);
        mImageButton.setEnabled(enabled);
        mTextButton.setEnabled(enabled);
        mCustomView.setEnabled(enabled);
    } 
 
    public void setDivider(ImageView divider) {
        mDivider = new WeakReference<ImageView>(divider);
    } 
 
    public void setVisible(boolean visible) {
        final int visibility = visible ? View.VISIBLE : View.GONE;
        if ((mDivider != null) && (mDivider.get() != null)) {
            mDivider.get().setVisibility(visibility);
        } 
        setVisibility(visibility);
    } 
 

7
CodeRank

Related ViewGroup getChildCount Questions & Answers:

getChildCount Method Overview
Returns the number of children in the group.
See Code Examples for other Android ViewGroup Methods: