FileDocCategorySizeDatePackage
ListWithEditTextHeaderTest.javaAPI DocAndroid 5.1 API3406Thu Mar 12 22:22:12 GMT 2015android.widget.listview.focus

ListWithEditTextHeaderTest

public class ListWithEditTextHeaderTest extends android.test.ActivityInstrumentationTestCase2

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

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

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

        TouchUtils.clickView(this, mListView.getChildAt(0));
        assertTrue("header does not have focus", mListView.getChildAt(0).isFocused());
        assertEquals("something is selected", AbsListView.INVALID_POSITION, mListView.getSelectedItemPosition());
    
public voidtestClickingHeaderWhenOtherItemHasFocusGivesHeaderFocus()

        sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
        assertEquals("selected position", 1, mListView.getSelectedItemPosition());
        TouchUtils.clickView(this, mListView.getChildAt(0));
        assertTrue("header does not have focus", mListView.getChildAt(0).isFocused());
        assertEquals("something is selected", AbsListView.INVALID_POSITION, mListView.getSelectedItemPosition());
    
public voidtestPreconditions()

        assertTrue("listview.getItemsCanFocus()", mListView.getItemsCanFocus());
        assertFalse("out of touch-mode", mListView.isInTouchMode());
        assertEquals("header view count", 1, mListView.getHeaderViewsCount());
        assertTrue("header does not have focus", mListView.getChildAt(0).isFocused());
    
public voidtestScrollingDoesNotDetachHeaderViewFromWindow()

        View header = mListView.getChildAt(0);
        assertNotNull("header is not attached to a window (?!)", header.getWindowToken());

        // Scroll header off the screen and back onto the screen
        int numItemsOnScreen = mListView.getChildCount();
        for (int i = 0; i < numItemsOnScreen; i++) {
            sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
        }
        for (int i = 0; i < numItemsOnScreen; i++) {
            sendKeys(KeyEvent.KEYCODE_DPAD_UP);
        }

        // Make sure the header was not accidentally left detached from its window
        assertNotNull("header has lost its window", header.getWindowToken());