FileDocCategorySizeDatePackage
ListSetSelectionTest.javaAPI DocAndroid 5.1 API2383Thu Mar 12 22:22:12 GMT 2015android.widget.listview

ListSetSelectionTest

public class ListSetSelectionTest extends android.test.ActivityInstrumentationTestCase2
Basic tests of setting & clearing the selection

Fields Summary
private ListSimple
mActivity
private android.widget.ListView
mListView
Constructors Summary
public ListSetSelectionTest()

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

        super.setUp();

        mActivity = getActivity();
        mListView = getActivity().getListView();
    
public voidtestClearSelection()
Confirm that you cannot unset the selection using the same API

        // Set the selection to first position
        mListView.setSelection(0);
        assertEquals("Set selection", 0, mListView.getSelectedItemPosition());

        // Clear the selection
        mListView.setSelection(ListView.INVALID_POSITION);
        assertEquals("Set selection", 0, mListView.getSelectedItemPosition());
    
public voidtestPreconditions()

        assertNotNull(mActivity);
        assertNotNull(mListView);
    
public voidtestSetSelection()
Confirm that we can set the selection to each specific position

        // Set the selection to each position
        int childCount = mListView.getChildCount();
        for (int i=0; i<childCount; i++) {
            mListView.setSelection(i);
            assertEquals("Set selection", i, mListView.getSelectedItemPosition());
        }