This Notes is according to the udacity free course :
Android Development for Beginners
Lesson 3A : Object Oriented Programming
Resources


There are 2 easy samples for you to understand what is Java class ?
These are the most important part of this section.
2. create object with factory methods (need to check out the object documentation)
The quiz focus on too much detail,so I provide the answer for you to check.
TextView textView = new TextView(context);
ImageView img = new ImageView(context);
ToggleButton button = new ToggleButton(context);
Toast toast = Toast.makeText(context, text, duration);
The different between object and class
reference:diffen
class is like a blue map for you to construct object
class can include many state and methods
Android Development for Beginners
Lesson 3A : Object Oriented Programming
Resources


What are Java objects
There are 2 easy samples for you to understand what is Java class ?
These are the most important part of this section.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Displays an image, such as an icon. | |
*/ | |
public class ImageView extends View { | |
// Resource ID for the source image that should be displayed in the ImageView. | |
private int mImageId; | |
// Context of the app | |
private Context mContext; | |
/** | |
* Constructs a new ImageView. | |
*/ | |
public ImageView(Context context) { | |
mImageId = 0; | |
mContext = context; | |
} | |
/** | |
* Sets the source image in the ImageView. | |
* | |
* @param imageId is the resource ID of the image to be displayed. | |
*/ | |
public void setImage(int imageId) { | |
mImageId = imageId; | |
} | |
} |
How to create object
1. create object with constructor(regular style)
2. create object with factory methods (need to check out the object documentation)
The quiz focus on too much detail,so I provide the answer for you to check.
TextView textView = new TextView(context);
ImageView img = new ImageView(context);
ToggleButton button = new ToggleButton(context);
Toast toast = Toast.makeText(context, text, duration);
The different between object and class
reference:diffen
class is like a blue map for you to construct object
class can include many state and methods
留言
張貼留言