-
Star
(102)
You must be signed in to star a gist -
Fork
(67)
You must be signed in to fork a gist
-
-
Save udacityandroid/47592c621d32450d7dbc to your computer and use it in GitHub Desktop.
/** | |
* Displays text to the user. | |
*/ | |
public class TextView extends View { | |
// String value | |
private String mText; | |
// Text color of the text | |
private int mTextColor; | |
// Context of the app | |
private Context mContext; | |
/** | |
* Constructs a new TextView with initial values for text and text color. | |
*/ | |
public TextView(Context context) { | |
mText = ""; | |
mTextColor = 0; | |
mContext = context; | |
} | |
/** | |
* Sets the string value in the TextView. | |
* | |
* @param text is the updated string to be displayed. | |
*/ | |
public void setText(String text) { | |
mText = text; | |
} | |
/** | |
* Sets the text color of the TextView. | |
* | |
* @param color of text to be displayed. | |
*/ | |
public void setTextColor(int color) { | |
mTextColor = color; | |
} | |
/** | |
* Gets the string value in the TextView. | |
* | |
* @return current text in the TextView. | |
*/ | |
public String getText() { | |
return mText; | |
} | |
/** | |
* Gets the text color of the TextView. | |
* | |
* @return current text color. | |
*/ | |
public int getTextColor() { | |
return mTextColor; | |
} | |
} |
Private and Protected?
private only accessable within the class
but , protected will accessable related derived class.
Was here in 2019
nICE
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
niceeee
good
2019
this course still relevant!!!
2019
this course still relevant!!!
Yes, very much! If a syntax is deprecated or changed in newer versions of android, android studio will help you with that. But those are very rare in this course. So don't worry, it is still very relevant :)
This is 2020...
This course might be outdated but it's still very relevant...
I was Here...
Was here! 💯
the course is still very relevant imo, it's very professional
It is brilliant))
what dose " @param" mean?
Hello everyone!
Was here 17/07/2020.
perfect
@bnil53 # https://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html
this is Controlling Access to Members of a Class
This link to the java documentation is very helpful, thanks for sharing.
super(context);
Thanks!!
What is difference between Private and Protected?
Private is something like variables or methods you can only access inside the class
Protected is accessible only with the help of child class.
Hi All
Why We Create Custom Class (Word)
Hi All
Why We Create Custom Class (Word)
So we can create our own customized view and use it whereever needed.
Hi All
Why We Create Custom Class (Word)So we can create our own customized view and use it whereever needed.
Thanks
Can we create a Custom Class without Definition of Constructor?
Hi All
Why We Create Custom Class (Word)So we can create our own customized view and use it whereever needed.
Thanks
Can we create a Custom Class without Definition of Constructor?
No constructor is needed to define its basic property.
thanks for the documentation
Where i have to write this i am not getting any idea
interesting
was here 2022
@RanaOsama25 context is essentially the key that grants access to information about your app. It is often passed to newly created objects, to let it know the current state of the app. Also, it is used to access the application-level info, via getApplicationContext(), getBaseContext(), getContext(), and using the keyword 'this'.
The particular file from which you are calling will determine which method can be used to get the context. For example, in the MainActivity.java, we can use getApplicationContext() or getBaseContext() (I believe each will provide the same application-level context, from within MainActivity.)
From other classes, to which a context has been passed, we can use that context to access the application context, via context.getApplicationContext()
the keyword 'this' can be a little tricky to understand. Generally, it refers to the Class in which it is called. So if you call this in the following snippet (you'll want to create a new class and copy and paste, to add the appropriate package name for your testApp.) You'll notice an ERROR for the first line of code within testMethod() following code, because this refers to the testClass class, not a Context (unless that class extends Context).
`import android.content.Context;
public class TestClass {
public void testMethod(Context context){
//will throw compile time error because here 'this' refers to the class TestClass
Context cont = this;
//'this' refers to containing class
TestClass test = this;
//way to get Context from the context passed into method from the calling code
Context context = context.getApplicationContext();
}
}`
By passing in a Context to this method, you can access the ApplicationContext. 'this' will refer to the containing Class. MainActivity is a special Class for Android framework, as one can see in the documentation, (for a number of reasons) but also because it extends Context (via a ContextWrapper), which means calling 'this' will implicitly give you a context.
From the android dev docs:
"It allows access to application-specific resources and classes, as well as up-calls for application-level operations such as launching activities, broadcasting and receiving intents, etc."
Here's a good stackOverflow answer: https://stackoverflow.com/questions/3572463/what-is-context-on-android
It's important to know that the keyword 'this' will perform differently in different contexts, as well as possibly vary between languages.
Hope this wasn't confusing. There's much to be learned about Context, but it will make more sense the more you practice.
-AAQ-AND-DEV (aaron Q.)