@Override

General topics about the Android-Platform itself.
Coding issues please to the subforum right below.

@Override

Postby Neondog » Wed Apr 28, 2010 10:12 pm

Hello all, I am new to developing on Android. I was wondering if someone could explain each line below and what it does? I understand how it works as a whole, just not sure what each part does

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  
  3.  
  4.     @Override \\What are we overriding?
  5.  
  6.      public void onCreate(Bundle icicle) { \\What is an icicle
  7.  
  8.           super.onCreate(icicle);
  9.  
  10.           this.setContentView(R.layout.main); \\I know this talks to the XML file but I dont understand how or what the connection is.
  11.  
  12.  
  13.  
  14.  
Parsed in 0.049 seconds, using GeSHi 1.0.8.4


Thanks in advance for your time.
Neondog
Junior Developer
Junior Developer
 
Posts: 10
Joined: Wed Apr 28, 2010 8:58 pm

Top

Re: @Override

Postby freewheelnat » Wed Apr 28, 2010 11:04 pm

Neondog wrote:Hello all, I am new to developing on Android. I was wondering if someone could explain each line below and what it does? I understand how it works as a whole, just not sure what each part does

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.     @Override \\What are we overriding?
  3.      public void onCreate(Bundle icicle) { \\What is an icicle
  4.           super.onCreate(icicle);
  5.           this.setContentView(R.layout.main); \\I know this talks to the XML file but I dont understand how or what the connection is.
  6.  
  7.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Thanks in advance for your time.


We are overriding the method onCreate defined for the class we extend (an Activity of some sort in this case)
"this" refers to the present context - in this case, the activity class. So we say "I want this activity to display the view contained in the xml file main"
freewheelnat
Developer
Developer
 
Posts: 40
Joined: Sat Aug 08, 2009 11:48 am
Location: London

?

Postby Neondog » Thu Apr 29, 2010 12:07 am

Thanks for the input freewheelnat, I appreciate it. So the extended class Activity has its own interface and we are overriding it? Either way, why do we need to override? Is the @Override specific to Java or the Dalvik VM? I found some of my answers by reading AndBook http://www.anddev.org/andbook/files/andbook.pdf , but it still left me with more questions. I understand what "super" and "this" mean, so that's a good sign. "R.layout.main" references the XML file...but how does it do that. Is "R.layout.main" a class that knows to grab the androidmanafest.xml and get certain parts of it? Again, thanks for your help.
Neondog
Junior Developer
Junior Developer
 
Posts: 10
Joined: Wed Apr 28, 2010 8:58 pm

Top

Return to General

Who is online

Users browsing this forum: No registered users and 4 guests