Basic Android

esse quam videri
Revision as of 20:09, 8 April 2014 by Jeff (talk | contribs) (Android Basics)
Jump to: navigation, search

Android Basics

after installing the plugin you may need to change the path to the SDK there is currently a bug if you us a folder with a space in the name use C:\PROGRA~2\Android\android-sdk if you installed to "C:\Program Files (x86)\Android"


  • src folder containing all the source
  • res folder containing all the resources

folder hierchy explained @


No DPI or PPI Andoid uses dp density independent pixels or sp scale interdependent pixels

also see supporting multiple screens


Activity life cycle

Get an instance of an object from the R class

<java>/** Called when the activity is first created. */

   public void onCreate(Bundle savedInstanceState) {
       //Get the Button and the TextView from the Resource class
       Button btn = (Button)this.findViewById(;
       final TextView tv = (TextView)this.findViewById(;  
       String s = "hello";


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>


Lots more good reading


Dog Class in java

public class Dog {

	public String Name;
	public int Weight;
	public String BarkSound;
	public Dog()
		this.Name = "fido";
		this.Weight = 1;
		this.BarkSound = "woof";
	public void Eat()
	public void Poop()
	public String About()
		return String.format("Hello my name is %s. I weigh %s lbs",	
				this.Name, this.Weight);

This text will be replaced