Hi - I am a beginning programmer, and I am on Chapter 4 now. There are some concepts that I still am not so clear on but I decided to venture on and hope that later chapters will cover these issues on my mind.
But by the time the book introduces Layouts, compound controls (or compound views... are they the same things?) and custom views, there are simply too many lines in code that I do not understand.
1. Context
ex.
Code:
public ClearableEditText(Context context)
I have no idea what Context class is, as well as why it needs to be passed into a View class such as ClearableEditText. Do I need to know this now or will it be introduced and explained in detail later?
2. onDraw & Canvas
ex. P. 93
Code:
@Override
Public void onDraw(Canvas canvas){
... }
is onDraw a method much like onCreate() where Android will automatically call for the class it is in (such as MyTextView)? do I assume that it is called immediately when the object is instantiated?
is Canvas a view? like Frame? or will it be introduced later in the book?
3. init() and Paint objects
ex. P. 95
Code:
private Paint marginPaint;
private Paint linePaint;
prviate int paperColor;
private float margin;
private void init()
//Get a reference to our resource table.
Resources myResources = getResources();
//Create the paint brushes we will use in the onDraw method.
marginPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
marginPaint.setColor(myResources.getColor(R.color.notepad_lines));
linePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
linePaint.setColor(myResources.getColor(R.color.notepad_lines));
//Get the paper background color and the margin width.
paperColor = myResources.getColor(R.color.notepad_paper);
margin = myResources.getDimension(R.dimen.notepad_margin);
}
Why do margin and line need the Paint class and papercolor and margin don't?
Where do I learn about the Paint class itself? Where is the init() method called when instantiating? Do you somehow indicate that method to be called in the TodoListItemView.java file?
Any help would be GREATLY appreciated. Thanks.