FileDocCategorySizeDatePackage
ListWithScreenOfNoSelectablesTest.javaAPI DocAndroid 5.1 API3950Thu Mar 12 22:22:12 GMT 2015android.widget.listview.arrowscroll

ListWithScreenOfNoSelectablesTest

public class ListWithScreenOfNoSelectablesTest extends android.test.ActivityInstrumentationTestCase2

Fields Summary
private android.widget.ListView
mListView
Constructors Summary
public ListWithScreenOfNoSelectablesTest()

        super(ListWithScreenOfNoSelectables.class);
    
Methods Summary
protected voidsetUp()

        super.setUp();
        mListView = getActivity().getListView();
    
public voidtestGoFromNoSelectionToSelectionExists()

        // go down untile first (and only selectable) item is off screen
        View first = mListView.getChildAt(0);
        while (first.getParent() != null) {
            sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
        }

        // nothing should be selected
        assertEquals("selected position", ListView.INVALID_POSITION, mListView.getSelectedItemPosition());
        assertNull("selected view", mListView.getSelectedView());

        // go up once to bring the selectable back on screen
        sendKeys(KeyEvent.KEYCODE_DPAD_UP);
        assertEquals("first visible position", 0, mListView.getFirstVisiblePosition());
        assertEquals("selected position", ListView.INVALID_POSITION, mListView.getSelectedItemPosition());


        // up once more should give it selection
        sendKeys(KeyEvent.KEYCODE_DPAD_UP);
        assertEquals("selected position", 0, mListView.getSelectedItemPosition());

    
public voidtestGoFromSelectedViewExistsToNoSelectedViewExists()


        // go down until first (and only selectable) item is off screen
        View first = mListView.getChildAt(0);
        while (first.getParent() != null) {
            sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
        }

        // nothing should be selected
        assertEquals("selected position", ListView.INVALID_POSITION, mListView.getSelectedItemPosition());
        assertNull("selected view", mListView.getSelectedView());
    
public voidtestPanDownAcrossUnselectableChildrenToBottom()

        final int lastPosition = mListView.getCount() - 1;
        final int maxDowns = 20;
        for(int count = 0; count < maxDowns && mListView.getLastVisiblePosition() <= lastPosition; count++) {
            sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
        }
        assertEquals("last visible position not the last position in the list even "
                + "after " + maxDowns + " downs", lastPosition, mListView.getLastVisiblePosition());
    
public voidtestPreconditions()

        assertTrue("expecting first position to be selectable",
                mListView.getAdapter().isEnabled(0));
        final int numItems = mListView.getCount();
        for (int i = 1; i < numItems; i++) {
            assertFalse("expecting item to be unselectable (index " + i +")",
                    mListView.getAdapter().isEnabled(i));
        }
        assertTrue("expecting that not all views fit on screen",
                mListView.getChildCount() < mListView.getCount());