How does end () work in an OnClick event?

I have Activityone button to exit Activity.

Through layout.xmlI need to set the event OnClickto cmd_exit, and calling this.finish () function works fine

public void cmd_exit(View editLayout){
    this.finish();
}

but when i add OnClickListenerinstead

cmd_exit = (Button) this.findViewById(R.id.cmd_ExitApp);
cmd_exit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
    finish();
    }
});

this.finish()gives an error. It should be only finish().

I understand that he finish()lives in the classroom Activity, so my question is: how does it work in the second fragment?

+4
source share
2 answers

OnClickListener , this , . YourActivityClassName.this. this, OnClickListener finish(), Activity.

+3

this Activity. anonymous inner, new View.OnClickListener(), this . , . finish(), .. OuterClassName.this.finish().

?

. , .


: Core Volume - , 9- , 6.4: , 309


@Gabe Sechan, , OuterClassName.this. : Java?.

+2

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


All Articles