1

I am a newbie in Android Development, how can I understand this snippets?

private OnClickListener listener = new OnClickListener() 
{   
    @Override
    public void onClick(View v)
    {
        // TODO Auto-generated method stub
        System.exit(0);
        finish();
    }
};

OnClickListener is a static interface, we can't use "new" to initialize an object. Who can help me, thank you in advance.

Artem Mostyaev
  • 3,874
  • 10
  • 53
  • 60
Kailani Yung
  • 45
  • 1
  • 8

1 Answers1

1

In Java, you can create an Anonymous Class if you implement all necessary requirements of the interface being presented. This is acting as a new class definition implementing OnClickListener, and overriding its one necessary method, onClick(View).

ballpointcarrot
  • 113
  • 1
  • 6