FileDocCategorySizeDatePackage
ListFocusableTest.javaAPI DocAndroid 5.1 API6182Thu Mar 12 22:22:12 GMT 2015android.widget.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.frameworks.coretests", 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());