You can download the source code for ActionBarSherlock, which should show you what you are looking for.
What is the private field name of actionbar context view ?
-
21-06-2023 - |
Question
A Hello ,,, I'm using robotium framework for testing android apps and I used Robotium-actionbarsherlock extension to perform clicks on contextual actionbar menu item ...
Here's the function I'm using ,,,
public void clickOnActionModeOverflowMenuItem(String text) {
Activity activity = solo.getCurrentActivity();
Log.d("aaaa", activity.toString());
if (!(activity instanceof SherlockFragmentActivity)) {
throw new IllegalStateException("This method should be called only in SherlockFragmentActivity.");
}
ActionBarContextView actionBarContextView = null;
try {
ActionBarSherlock actionBarSherlock = (ActionBarSherlock) invokePrivateMethodWithoutParameters(
SherlockFragmentActivity.class, "getSherlock", activity);
Log.d("eeee", actionBarSherlock.toString());
actionBarContextView = (ActionBarContextView) getPrivateField("mActionModeView", actionBarSherlock);
Log.d("dddd", actionBarContextView.toString());
} catch (Exception ex) {
Log.d(LOG_TAG, "Can not find methods to invoke action mode overflow button.");
}
if (actionBarContextView == null) {
Assert.fail("Contextual actionbar is not shown.");
}
actionBarContextView.showOverflowMenu();
sleeper.sleep();
clicker.clickOnText(text, false, 1, true, 0);
}
So, I'm asking about this line ..
actionBarContextView = (ActionBarContextView) getPrivateField("mActionModeView", actionBarSherlock);
How can I know the private field name ? As the function fails and throws the assertion fail of null actionBarContextView ...
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow