-
-
Save udacityandroid/bd550cc8fd37190d85a6 to your computer and use it in GitHub Desktop.
/** | |
* 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; | |
} | |
} |
They finally gave up on explaining stuff and started using jargons, like what is a constructor dude?! you never mentioned it before...
I knew this would happen at some point.
@Stannisseaworth In class-based object-oriented programming, a constructor (abbreviation: ctor) in a class is a special type of subroutine called to create an object. It prepares the new object for use, often accepting arguments that the constructor uses to set required member variables.
@Stannisseaworth I know how it feels, had the same issue when I first started learning programming. Will try to explain it non-programming way. A constructor is like the laws of a society. Before you create the society (objects), you have to define the laws what you can eat, do, etc etc (parameters and arguments) and write them down on an official piece of paper (magic methods). The society would then run and revolved based on those pieces of paper and laws. This is why they are called constructors. Hope I got this right.
Correction ;
public ImageView(Context context) { super(context); mImageId = 0; mContext = context; }
in place of setImage method there is src to set image.
A constructor is a method that is called or invoked when the object is created. A class is just the blueprint of an object.
helpful ..thanks
Simple example helpful!
nice
nice
nice
helpful
Seems errors noticed by our predecessors have been corrected. Nice work
Thanks.
thanks
Thanks
TNX
thanks ♥
please can anyone explain why the member variables they used were declared private access modifier
private int mImageId;
**private** Context mContext;
please can anyone explain why the member variables they used were declared private access modifier
private int mImageId;**private** Context mContext;
I copied the answer from the other site:
What is difference between Private and Protected?
Private get only used in his class , but protected can used in his class and in the same package and derived class
Was here!
I think there is no setImage() method in the ImageView class. Its setImageResource() .