Difference between revisions of "Basic Android"
(→Activities) |
(→Activities) |
||
Line 49: | Line 49: | ||
} | } | ||
</java> | </java> | ||
− | notice the cast to the type also notice that the TextView is marked as [http://en.wikipedia.org/wiki/Final_%28Java%29 final] this is so that we can use it in an inner method | + | notice the cast to the type also notice that the TextView is marked as [http://en.wikipedia.org/wiki/Final_%28Java%29 final] |
+ | this is so that we can use it in an inner method | ||
handle a click event | handle a click event |
Revision as of 16:45, 19 July 2011
Android Basics
- Install 32 bit Java JDK http://www.oracle.com/technetwork/java/javase/downloads/index.html
- App Inventor Pretty basic web interface an blocks editor to build simple android apps http://appinventor.googlelabs.com/about/
- Setup App Inventor http://appinventor.googlelabs.com/learn/setup/
- Android SDK
- http://developer.android.com/sdk/index.html
- Install SDK Installer http://developer.android.com/sdk/tools-notes.html
- Install Eclipse http://www.eclipse.org/downloads/
- Install Eclipse ADT Plugin http://developer.android.com/sdk/eclipse-adt.html#installing
- Android NDK
- we're not covering this http://developer.android.com/sdk/ndk/index.html
Basics
- src folder containg all the source
- res folder containing all the resources
Resources
No DPI or PPI Andoid uses dp density independent pixels or sp scale interdependent pixels http://developer.android.com/guide/topics/resources/more-resources.html#Dimension
also see supporting multiple screens http://developer.android.com/guide/practices/screens_support.html
Activities
Activity life cycle http://developer.android.com/guide/topics/fundamentals/activities.html#Lifecycle
Get an instance of an object from the R class
<java>/** Called when the activity is first created. */
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //Get the Button and the TextView from the Resource class Button btn = (Button)this.findViewById(R.id.button1); final TextView tv = (TextView)this.findViewById(R.id.textView1); String s = "hello"; tv.setText(s); }
</java>
notice the cast to the type also notice that the TextView is marked as final this is so that we can use it in an inner method
handle a click event <java> btn.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) { // TODO Auto-generated method stub tv.setText(d.About()); } });</java>
Events
Lots more good reading http://developer.android.com/guide/topics/fundamentals.html