I want to know the difference between view and View in "import android.view.View"statement.My confusion is whether View is a package or a class. If View is a class, what is View.OnClickListener
5 Answers
In java a name starting with a capital letter is always a class, interface or enum. Everything else starts with a lower case letter.
In that case when you have lower.lower.Capital1.Capital2 it means that there is a class, interface or enum inside class Capital1
Code example:
package pack;
public class Name {
public static void m1(){
//Method
}
public class InnerClass{ }
public interface InnerInterface{
public void m2(); //method interface
}
public enum InnerEnum{
VAL1, VAL2
}
}
Here we can have pack.Name
, pack.Name.m1
, pack.Name.InnerClass
, pack.Name.InnerInterface
and pack.Name.InnerEnum
EDIT:
As Taslim Oseni pointed out - this is just a convention and you don't have to follow it. Most companies however do follow convention. As a matter of fact most good IDEs display warnings when code does not follow the convention.

- 567
- 6
- 15
-
In java, a name starting with a capital letter is **NOT** always a class. This is only a convention and NOT A RULE. Most standard libraries follow this convention but it is still very possible to find libraries that don't. – Taslim Oseni Jul 31 '19 at 12:26
-
1You're right - In fact where I work convention is a very loose suggestion that is often ignored. But in general big companies follow the convention (especially that good IDEs complain about names not following conventions). I'll edit my answer to add that note – Miku Jul 31 '19 at 12:43
-
Yeah.. Awesome! – Taslim Oseni Jul 31 '19 at 12:48
View.OnClickListener is an interface, you don't call it, but creates a new instance of it (new View.OnClickListener() is a call to the constructor)
The instance you create is of anonymous class that implements View.OnClickListener, in the brackets right under new View.OnClickListener()
Any class that implements View.OnClickListener must implement the methods declared in it (e.g. onClick)
setOnClickListener just saves the reference to the View.OnClickListener instance you supplied, and when someone clicks the button, the onClick method of the listener you set is getting called.
Simply extracted from another question on StackOverflow : link here.
In other words, View is a class that is composed of multiple methods. One of theme is called OnClickListener. When you implement it and apply it on a Button for example (button.setOnClickListener(this)
), you will get an event when this button is clicked. The event is send to your current activity or fragment (this), you can catch in by overriding method onClick.

- 988
- 2
- 8
- 19
Based on my understanding, view is a package and View is a class.
view package contains a lot other classes like animations, transformations, and accessibility.
View is a class that represents user interface components like Button, TextView, EditText ... It will be draw on the user screen to convey message to users.
View.OnClickListener is an interface in View class to detect user click event on the view. Since most of the UI elements extends View, they will be able to implement this function to detect click event perform on them.
For example, Button class extends TextView which extends View, thus we can do like
MyButton.setOnClickListener

- 829
- 8
- 20
android.view is package and `.View` is a class
View.OnClickListene
is an interface inside ViewClass

- 3,868
- 1
- 20
- 26
view is a robust package that contains a lot of classes, interfaces, annotations, enums and exceptions. The view package typically handles all forms of screen layouts as well as their interactions with the user.
The View class is one of the many classes contained in the view
package. It is basically the building block of every user interface component (Buttons, ImageViews, LinearLayouts, etc).
If View is a class, what is View.OnClickListener
View.OnClickListener is an interface of the View class. All it does is to invoke a callback when the view is clicked.
I hope this helps.. Merry coding!

- 6,086
- 10
- 44
- 69