FileDocCategorySizeDatePackage
ListFocusableTest.javaAPI DocAndroid 1.5 API6186Wed May 06 22:42:02 BST 2009com.android.frameworktest.listview

ListFocusableTest

public class ListFocusableTest extends android.test.ActivityInstrumentationTestCase

Fields Summary
private ListTopGravity
mActivity
private android.widget.ListView
mListView
Constructors Summary
public ListFocusableTest()

        super("com.android.frameworktest", ListTopGravity.class);
    
Methods Summary
private android.widget.ListAdaptercreateEmptyAdapter()

        return new ArrayAdapter<String>(mActivity, android.R.layout.simple_list_item_1,
                new String[] { });
    
private android.widget.ListAdaptercreateFullAdapter()

        return new ArrayAdapter<String>(mActivity, android.R.layout.simple_list_item_1,
                new String[] { "Android", "Robot" });
    
private voidsetEmptyAdapter()

        mActivity.runOnUiThread(new Runnable() {
            public void run() {
                mListView.setAdapter(createEmptyAdapter());
            }
        });
        getInstrumentation().waitForIdleSync();
    
private voidsetFocusable()

        mActivity.runOnUiThread(new Runnable() {
            public void run() {
                mListView.setFocusable(true);
            }
        });
        getInstrumentation().waitForIdleSync();
    
private voidsetFullAdapter()

        mActivity.runOnUiThread(new Runnable() {
            public void run() {
                mListView.setAdapter(createFullAdapter());
            }
        });
        getInstrumentation().waitForIdleSync();
    
private voidsetNonFocusable()

        mActivity.runOnUiThread(new Runnable() {
            public void run() {
                mListView.setFocusable(false);
            }
        });
        getInstrumentation().waitForIdleSync();
    
private voidsetNullAdapter()

        mActivity.runOnUiThread(new Runnable() {
            public void run() {
                mListView.setAdapter(null);
            }
        });
        getInstrumentation().waitForIdleSync();
    
protected voidsetUp()

        super.setUp();

        mActivity = getActivity();
        mListView = getActivity().getListView();
    
public voidtestAdapterEmpty()

        setEmptyAdapter();
        assertFalse(mListView.isFocusable());
    
public voidtestAdapterEmptySetFocusable()

        setEmptyAdapter();
        assertFalse(mListView.isFocusable());

        setFocusable();
        assertFalse(mListView.isFocusable());
    
public voidtestAdapterEmptySetNonFocusable()

        setEmptyAdapter();
        assertFalse(mListView.isFocusable());

        setNonFocusable();
        assertFalse(mListView.isFocusable());
    
public voidtestAdapterFull()

        setFullAdapter();
        assertTrue(mListView.isFocusable());
    
public voidtestAdapterFullSetFocusable()

        assertTrue(mListView.isFocusable());

        setFocusable();
        assertTrue(mListView.isFocusable());
    
public voidtestAdapterFullSetNonFocusable()

        assertTrue(mListView.isFocusable());

        setNonFocusable();
        assertFalse(mListView.isFocusable());
    
public voidtestAdapterNull()

        setNullAdapter();
        assertFalse(mListView.isFocusable());
    
public voidtestAdapterNullSetFocusable()

        setNullAdapter();
        assertFalse(mListView.isFocusable());

        setFocusable();
        assertFalse(mListView.isFocusable());
    
public voidtestAdapterNullSetNonFocusable()

        setNullAdapter();
        assertFalse(mListView.isFocusable());

        setNonFocusable();
        assertFalse(mListView.isFocusable());
    
public voidtestFocusableSetAdapterEmpty()

        assertTrue(mListView.isFocusable());

        setEmptyAdapter();
        assertFalse(mListView.isFocusable());
    
public voidtestFocusableSetAdapterFull()

        assertTrue(mListView.isFocusable());

        setFullAdapter();
        assertTrue(mListView.isFocusable());
    
public voidtestFocusableSetAdapterNull()

        assertTrue(mListView.isFocusable());

        setNullAdapter();
        assertFalse(mListView.isFocusable());
    
public voidtestNonFocusableSetAdapterEmpty()

        assertTrue(mListView.isFocusable());

        setNonFocusable();
        assertFalse(mListView.isFocusable());

        setEmptyAdapter();
        assertFalse(mListView.isFocusable());
    
public voidtestNonFocusableSetAdapterFull()

        assertTrue(mListView.isFocusable());

        setNonFocusable();
        assertFalse(mListView.isFocusable());

        setFullAdapter();
        assertFalse(mListView.isFocusable());
    
public voidtestNonFocusableSetAdapterNull()

        assertTrue(mListView.isFocusable());

        setNonFocusable();
        assertFalse(mListView.isFocusable());

        setNullAdapter();
        assertFalse(mListView.isFocusable());
    
public voidtestPreconditions()

        assertNotNull(mActivity);
        assertNotNull(mListView);

        // First item should be selected
        assertEquals(0, mListView.getSelectedItemPosition());