Code example for Instrumentation

Methods: runOnMainSyncsendKeyDownUpSyncwaitForIdleSync, sleep

0
        instr = testCase.getInstrumentation();
    } 
 
    public static void sleep(long msec) {
        try { 
            Thread.sleep(msec);
        } 
        catch (InterruptedException e) {
            throw new RuntimeException(e);
        } 
    } 
 
    public static void selectListAndMoveToTop(final ListView list) {
        instr.runOnMainSync(
            new Runnable() {
                public void run() { 
                    list.requestFocus();
                } 
            }); 
 
        instr.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_UP);
        instr.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_UP);
        instr.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_UP);
        instr.waitForIdleSync();
 
        sleep(500); 
    } 
 
    public static void selectCurrent() {