0

I'm new to android. According to the code below, if onListItemClick is a super class method, then why override is not used? and if it's a subclass method, then why when i change the method name, app crashes?!

class BasicViews5Activity extends ListActivity{

    //onCreate method here

public void onListItemClick(ListView parent, View v, int position, long id){
   //some code here
}
}
xvx ph
  • 69
  • 1
  • 2
  • 12
  • possible duplicate of [When do you use Java's @Override annotation and why?](http://stackoverflow.com/questions/94361/when-do-you-use-javas-override-annotation-and-why) – Tobias Sep 05 '15 at 14:54

1 Answers1

0

The class ListActivity contains a method

 protected void onListItemClick (ListView l, View v, int position, long id)

Therefore, your own implementation of that method in a class inheriting from ListActivity overrides the super class method.

In JAVA (and Android), the @Override annotation is optional. Have a look at this question to find out more about the annotation and when to use it (short answer: always use @Override).

Community
  • 1
  • 1
Tobias
  • 7,723
  • 1
  • 27
  • 44