Difference between revisions of "Basic Android"

esse quam videri
Jump to: navigation, search
(Dog Class in java)
Line 79: Line 79:
==Dog Class in java==
==Dog Class in java==
<syntaxhighlight lang="java">
public class Dog {
public class Dog {
Line 111: Line 111:
</syntaxhighlight lang="java">>
=In Class Demo=
=In Class Demo=

Revision as of 16:15, 4 April 2016

Android Basics


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

folder hierarchy explained http://developer.android.com/tools/projects/index.html

First app demo http://developer.android.com/training/basics/firstapp/running-app.html

App lifecycle http://developer.android.com/guide/components/activities.html



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


Activity life cycle http://developer.android.com/guide/topics/fundamentals/activities.html#Lifecycle

Get an instance of an object from the R class

/** 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(R.id.button1);
        final TextView tv = (TextView)this.findViewById(R.id.textView1);  
        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

btn.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				// TODO Auto-generated method stub


Lots more good reading http://developer.android.com/guide/topics/fundamentals.html


Dog Class in java

<syntaxhighlight lang="java"> public class Dog {

public String Name; public int Weight; public String BarkSound;

//Constructor public Dog() { this.Name = "fido"; this.Weight = 1; this.BarkSound = "woof"; }

public void Eat() { this.Weight++; } public void Poop() { this.Weight--; }

public String About() { return String.format("Hello my name is %s. I weigh %s lbs", this.Name, this.Weight); }

} </syntaxhighlight lang="java">>

In Class Demo