Code example for GridView

Methods: getAdapter, getSelectedItemPosition

0
    public void testPreconditions() { 
        assertNotNull(mActivity);
        assertNotNull(mGridView);
 
        // Last item should be selected 
        assertEquals(mGridView.getAdapter().getCount() - 1, mGridView.getSelectedItemPosition());
 
    } 
 
    @MediumTest 
    public void testNoScroll() { 
        View firstChild = mGridView.getChildAt(0);
        View lastChild = mGridView.getChildAt(mGridView.getChildCount() - 1);
         
        int lastTop = lastChild.getTop();
         
        TouchUtils.dragViewBy(this, firstChild, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0,
                ViewConfiguration.getTouchSlop());
         
        View newLastChild = mGridView.getChildAt(mGridView.getChildCount() - 1);
Stop searching for code, let great code find you!  Add Codota to your java IDE