Reputation: 137
I don't understand in this rule. One year ago, I learn OOP from C# book. So, I learn C# OOP. When I programming java, it's take little effort to understand java codes. But, when I move to android. I find few strange things. like classname.this, object.this, constructor where its parameter is interface. I think android is not easy, if I have problem where the problem is never asked in stackoverflow, I think I will dead. Because, I can't understand all methods in android library(android library documentation). When I read in documentation, I just understand few of all methods, I understand definitions of many methods. But I always confuse when I try understand parameters of method.
I want to ask. . .
Why this is right :
final EditText textBoxSearch = (EditText) findViewById(R.id.textbox_search);
textBoxSearch.setVisibility(EditText.GONE);
And why this is not right :
textBoxSearch.setVisibility(textBoxSearch.GONE);
Upvotes: 0
Views: 113
Reputation: 12243
GONE
is a static variable, not an instance variable, so you need to do class.GONE
. It comes from View
, which EditText
subclasses.
Basically, it belongs to the class rather than the instance.
This is the same behavior as static variables in Java:
Sometimes, you want to have variables that are common to all objects. This is accomplished with the static modifier. Fields that have the static modifier in their declaration are called static fields or class variables. They are associated with the class, rather than with any object. Every instance of the class shares a class variable, which is in one fixed location in memory. Any object can change the value of a class variable, but class variables can also be manipulated without creating an instance of the class.
Class variables are referenced by the class name itself [...].
Upvotes: 3
Reputation: 93581
I'm kind of the opposite of you...I learned Java first and only know a little bit of C#. But as far as I know, this is very similar between both of them.
EditText.GONE is a static final variable (like a const in C).
A simple way to think of it is that for every class, you have all the instances you can instantiate from it, but you also have a unique object for the class itself, and that object is what has all the static variables and methods in it.
Upvotes: 0