Programmatically click the Finish button in the contextual action bar.

How can I programmatically click the Finish button in the contextual action bar? Or, specifically, idfor this button? If I know so much, I can use Robotium to click on it.

Update:

hierarchyviewershows an attribute mIdwith a value NO_ID, so now I need help with my original question. Does anyone have any other ideas on how to do this? In particular, I need to click the "Finish" button during the test.

+4
source share
2 answers

Or, more precisely, what is the identifier for this button?

, , action_mode_close_button.

"" ?

View.performClick. View , , null. Runnable ListView , , ActionMode. :

        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            mList.postDelayed(new Runnable() {

                @Override
                public void run() {
                    findViewById(android.R.id.action_mode_close_button).performClick();
                }
            }, 1000);
            return true;
        }
+1

, , .

int doneButtonId = Resources.getSystem().getIdentifier("action_mode_close_button", "id", "android");
View doneButton = getActivity().findViewById(doneButtonId);

if(doneButton != null && doneButton.isClickable(){
doneButton.performClick();
}

, .isClickable(), , , .

0

Source: https://habr.com/ru/post/1546458/


All Articles