FileDocCategorySizeDatePackage
ListUtil.javaAPI DocAndroid 1.5 API3225Wed May 06 22:42:02 BST 2009com.android.frameworktest.util

ListUtil

public class ListUtil extends Object
Various useful stuff for instrumentation testing listview.

Fields Summary
private final android.widget.ListView
mListView
private final android.app.Instrumentation
mInstrumentation
Constructors Summary
public ListUtil(android.widget.ListView listView, android.app.Instrumentation instrumentation)

param
listView The listview to act on
param
instrumentation The instrumentation to use.

        mListView = listView;
        mInstrumentation = instrumentation;
    
Methods Summary
private voidarrowDownToSelectedPosition(int position)

        int maxDowns = 20;
        while(mListView.getSelectedItemPosition() < position && --maxDowns > 0) {
            mInstrumentation.sendCharacterSync(KeyEvent.KEYCODE_DPAD_DOWN);
        }
        if (position != mListView.getSelectedItemPosition()) {
            throw new IllegalStateException("couldn't get to item after 20 downs");
        }

    
public final voidarrowScrollToSelectedPosition(int desiredPos)
Arrow (up or down as appropriate) to the desired position in the list.

param
desiredPos The desired position
throws
IllegalStateException if the position can't be reached within 20 presses.

        if (desiredPos > mListView.getSelectedItemPosition()) {
            arrowDownToSelectedPosition(desiredPos);
        } else {
            arrowUpToSelectedPosition(desiredPos);
        }
    
private voidarrowUpToSelectedPosition(int position)

        int maxUps = 20;
        while(mListView.getSelectedItemPosition() > position && --maxUps > 0) {
            mInstrumentation.sendCharacterSync(KeyEvent.KEYCODE_DPAD_UP);
        }
        if (position != mListView.getSelectedItemPosition()) {
            throw new IllegalStateException("couldn't get to item after 20 ups");
        }
    
public final intgetListBottom()
Get the bottom of the list.

        return mListView.getHeight() - mListView.getListPaddingBottom();
    
public final intgetListTop()
Get the top of the list.

        return mListView.getListPaddingTop();
    
public final voidsetSelectedPosition(int pos)
Set the selected position of the list view.

param
pos The desired position.

        mListView.post(new Runnable() {
            public void run() {
                mListView.setSelection(pos);
            }
        });
        mInstrumentation.waitForIdleSync();