Issue
In my activity test I need to verify that a menu item has certain title.
I can get it by ID but it returns a view.
final View menuItem = (View) mActivity.findViewById(R.id.do_it);
But how can I get the title from this view then?
Note: I need to do it in ActivityInstrumentationTestCase2 test.
Update
I am hoping to find a way to get menu item's title in my test case without writing any additional code in activity, like storing menu in a variable.
Solution
Use getTitle()
:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.<manuLayout>, menu);
MenuItem menuItem = menu.findItem(R.id.do_it);
String title = menuItem.getTitle();
return true;
}
Answered By - Green goblin
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.