Gintas_
Gintas_

Reputation: 5030

How to call super method in interface instance?

@Override
public void onBackPressed()
{
    // ...
    dialog.setPositiveButton(getText(R.string.yes), new OnClickListener()
    {
        @Override
        public void onClick(DialogInterface dialog, int which)
        {
            super.onBackPressed();
        }
    });
}

Gives me error on super line and I completely understand why. But how can I fix it?

Upvotes: 0

Views: 710

Answers (1)

nhaarman
nhaarman

Reputation: 100378

super.onBackPressed in your example refers to OnClickListener#onBackPressed, which just doesn't exist, hence your error.

You actually want to reference the onBackPressed of your super Activity class. To do that, use:

MyActivity.super.onBackPressed();

Just like MyActivity.this refers to the enclosing instance, MyActivity.super refers to the super class of the enclosing instance.

Upvotes: 5

Related Questions