Code example for Button

Methods: requestFocus

0
        // This is in contrast to instrumentation calls that send events that are 
        // processed through the framework and eventually find their way to 
        // affecting the ui thread. 
        getActivity().runOnUiThread(new Runnable() {
            public void run() { 
                mRightButton.requestFocus();
            } 
        }); 
        // wait for the request to go through 
        getInstrumentation().waitForIdleSync();
 
        assertTrue(mRightButton.isFocused());
 
        sendKeys(KeyEvent.KEYCODE_DPAD_LEFT);
        assertTrue("center button should be focused", mCenterButton.isFocused());
    } 
}