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

This code example shows how to use the following methods:getChildAt, performItemClick, getAdapter
	} 
 
	@Test 
	public void is_item_click_available_from_list_fragment() { 
		ListView listView = (ListView) myListFragment.findViewById(android.R.id.list);
		long itemId = listView.getAdapter().getItemId(TESTED_CLICKED_INDEX);
		View view = listView.getChildAt(TESTED_CLICKED_INDEX);
 
		assertThat(myListFragment.listItemClicked).isFalse();
		listView.performItemClick(view, TESTED_CLICKED_INDEX, itemId);
		assertThat(myListFragment.listItemClicked).isTrue();
	} 
 
	public static void startFragment(Fragment fragment) {
		FragmentManager fragmentManager = new FragmentActivity().getSupportFragmentManager();
		FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
		fragmentTransaction.add(fragment, null);
		fragmentTransaction.commit();
	} 
} 
7
CodeRank
This code example shows how to use the following methods:getChildAt, getFirstVisiblePosition
 
	protected void onListItemClick (ListView listView, View view, int position, long id) {
		super.onListItemClick(listView, view, position, id);
 
		Editor editor = prefs.edit();
		editor.putInt("index", listView.getFirstVisiblePosition());
		editor.putInt("top", listView.getChildAt(0) == null ? 0 : listView.getChildAt(0).getTop());
		editor.commit();
 
		Object o = this.getListAdapter().getItem(position);
		String testName = o.toString();
 
		Bundle bundle = new Bundle();
		bundle.putString("test", testName);
		Intent intent = new Intent(this, GdxTestActivity.class);
		intent.putExtras(bundle);
 
		startActivity(intent);
	} 
 
8
CodeRank
This code example shows how to use the following methods:getContext, getChildAt, getHeaderViewsCount, getFirstVisiblePosition
     * This simple implementation creates a Bitmap copy of the list item 
     * currently shown at ListView <code>position</code>. 
     */ 
    @Override 
    public View onCreateFloatView(int position) {
        View v = mListView.getChildAt(position + mListView.getHeaderViewsCount()
                - mListView.getFirstVisiblePosition());
 
        if (v == null) {
            return null; 
        } 
 
        v.setPressed(false);
 
        v.setDrawingCacheEnabled(true);
        mFloatBitmap = Bitmap.createBitmap(v.getDrawingCache());
        v.setDrawingCacheEnabled(false);
 
        ImageView iv = new ImageView(mListView.getContext());
        iv.setBackgroundColor(mFloatBGColor);

8
CodeRank
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:isInTouchMode, getChildAt, getHeaderViewsCount, getItemsCanFocus
        mListView = getActivity().getListView();
    } 
 
    @MediumTest 
    public void testPreconditions() { 
        assertTrue("listview.getItemsCanFocus()", mListView.getItemsCanFocus());
        assertFalse("out of touch-mode", mListView.isInTouchMode());
        assertEquals("header view count", 1, mListView.getHeaderViewsCount());
        assertTrue("header has focus", mListView.getChildAt(0).isFocused());
    } 
 
    @FlakyTest(tolerance=2) 
    @LargeTest 
    public void testClickingHeaderKeepsFocus() { 
        TouchUtils.clickView(this, mListView.getChildAt(0));
        assertTrue("header has focus", mListView.getChildAt(0).isFocused());
        assertEquals("nothing selected", AbsListView.INVALID_POSITION, mListView.getSelectedItemPosition());
    } 
 
    @LargeTest 
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: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

Related ViewGroup getChildAt Questions & Answers:

getChildAt Method Overview
Returns the view at the specified position in the group.
See Code Examples for other Android ViewGroup Methods: