FileDocCategorySizeDatePackage
GridSetSelectionBaseTest.javaAPI DocAndroid 5.1 API3289Thu Mar 12 22:22:12 GMT 2015android.widget.gridview

GridSetSelectionBaseTest

public class GridSetSelectionBaseTest extends android.test.ActivityInstrumentationTestCase

Fields Summary
private T
mActivity
private android.widget.GridView
mGridView
Constructors Summary
protected GridSetSelectionBaseTest(Class klass)

        super("com.android.frameworks.coretests", klass);
    
Methods Summary
protected voidsetUp()

        super.setUp();

        mActivity = getActivity();
        mGridView = getActivity().getGridView();
    
public voidtestPreconditions()

        assertNotNull(mActivity);
        assertNotNull(mGridView);

        // First item should be selected
        if (mGridView.isStackFromBottom()) {
            assertEquals(mGridView.getAdapter().getCount() - 1,
                    mGridView.getSelectedItemPosition());
        } else {
            assertEquals(0, mGridView.getSelectedItemPosition());
        }
    
public voidtestSetSelectionToMiddle()

        final int target = mGridView.getAdapter().getCount() / 2;
        mActivity.runOnUiThread(new Runnable() {
            public void run() {
                mGridView.setSelection(target);
            }
        });
        getInstrumentation().waitForIdleSync();

        assertEquals(mGridView.getSelectedItemPosition(), target);
        assertNotNull(mGridView.getSelectedView());

        ViewAsserts.assertOnScreen(mGridView, mGridView.getSelectedView());
    
public voidtestSetSelectionToTheEnd()

        final int target = mGridView.getAdapter().getCount() - 1;
        mActivity.runOnUiThread(new Runnable() {
            public void run() {
                mGridView.setSelection(target);
            }
        });
        getInstrumentation().waitForIdleSync();

        assertEquals(mGridView.getSelectedItemPosition(), target);
        assertNotNull(mGridView.getSelectedView());

        ViewAsserts.assertOnScreen(mGridView, mGridView.getSelectedView());
    
public voidtestSetSelectionToTheTop()

        mActivity.runOnUiThread(new Runnable() {
            public void run() {
                mGridView.setSelection(0);
            }
        });
        getInstrumentation().waitForIdleSync();

        assertEquals(mGridView.getSelectedItemPosition(), 0);
        assertNotNull(mGridView.getSelectedView());

        ViewAsserts.assertOnScreen(mGridView, mGridView.getSelectedView());