문제

I have a FrameLayout defined in xml with:

android:onClick="cancel"

The activity that creates the ActionBar has a method that looks like:

public void cancel ( View view ) {
// Do stuff
}

However, when I click the "button", I get: could not find a method cancel(View) in the activity class android.view.ContextThemeWrapper for onClick handler...

...what gives?

도움이 되었습니까?

해결책

Apparently this is how it's done:

    FrameLayout cancelButton = ( FrameLayout ) actionBar.getCustomView ().findViewById ( R.id.actionbar_cancel );

    cancelButton.setOnClickListener ( new OnClickListener () {

        @Override
        public void onClick ( View v ) {
            // DO STUFF
        }
    } );
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top