FileDocCategorySizeDatePackage
ExpandableListBasicTest.javaAPI DocAndroid 1.5 API4704Wed May 06 22:42:02 BST 2009com.android.frameworktest.expandablelistview

ExpandableListBasicTest

public class ExpandableListBasicTest extends android.test.ActivityInstrumentationTestCase

Fields Summary
private com.android.frameworktest.util.ExpandableListScenario
mActivity
private android.widget.ExpandableListView
mListView
private android.widget.ExpandableListAdapter
mAdapter
private com.android.frameworktest.util.ListUtil
mListUtil
Constructors Summary
public ExpandableListBasicTest()

        super("com.android.frameworktest",
                ExpandableListSimple.class);
    
Methods Summary
private intexpandGroup(int numChildren, boolean atLeastOneChild)

        final int groupPos = mActivity.findGroupWithNumChildren(numChildren, atLeastOneChild);
        
        assertTrue("Could not find group to expand", groupPos >= 0);
        assertFalse("Group is already expanded", mListView.isGroupExpanded(groupPos));
        mListUtil.arrowScrollToSelectedPosition(groupPos);
        getInstrumentation().waitForIdleSync();
        sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);
        getInstrumentation().waitForIdleSync();
        assertTrue("Group did not expand", mListView.isGroupExpanded(groupPos));
        
        return groupPos;
    
protected voidsetUp()

        super.setUp();
        
        mActivity = getActivity();
        mListView = mActivity.getExpandableListView();
        mAdapter = mListView.getExpandableListAdapter();
        mListUtil = new ListUtil(mListView, getInstrumentation());
    
public voidtestCollapseGroup()

        final int groupPos = expandGroup(-1, true);
        
        sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);
        getInstrumentation().waitForIdleSync();
        assertFalse("Group did not collapse", mListView.isGroupExpanded(groupPos));
    
public voidtestExpandGroup()

        expandGroup(-1, true);
    
public voidtestExpandedGroupMovement()


        // Expand the first group
        mListUtil.arrowScrollToSelectedPosition(0);
        sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);
        getInstrumentation().waitForIdleSync();

        // Ensure it expanded
        assertTrue("Group did not expand", mListView.isGroupExpanded(0));
        
        // Wait until that's all good
        getInstrumentation().waitForIdleSync();
        
        // Make sure it expanded
        assertTrue("Group did not expand", mListView.isGroupExpanded(0));
        
        // Insert a collapsed group in front of the one just expanded
        List<MyGroup> groups = mActivity.getGroups();
        MyGroup insertedGroup = new MyGroup(1);
        groups.add(0, insertedGroup);
        
        // Notify data change
        assertTrue("Adapter is not an instance of the base adapter",
                mAdapter instanceof BaseExpandableListAdapter);
        final BaseExpandableListAdapter adapter = (BaseExpandableListAdapter) mAdapter;
     
        mActivity.runOnUiThread(new Runnable() {
            public void run() {
                adapter.notifyDataSetChanged();
            }
        });
        getInstrumentation().waitForIdleSync();
        
        // Make sure the right group is expanded
        assertTrue("The expanded state didn't stay with the proper group",
                mListView.isGroupExpanded(1));
        assertFalse("The expanded state was given to the inserted group",
                mListView.isGroupExpanded(0));
    
public voidtestPreconditions()

        assertNotNull(mActivity);
        assertNotNull(mListView);