The thing to understand here is that:
The constructor ViewClassName(Context context, AttributeSet attrs )
is called when inflating the customView via xml.
You see you are not using the new keyword to instantiate your object i.e. you are not doing new GhostSurfaceCameraView()
. Doing this you are calling the first constructor i.e. public View (Context context)
.
Whereas when inflating view from XML, i.e. when using setContentView(R.layout.ghostviewscreen);
or using findViewById
, you, NO, not you!, the android system calls the ViewClassName(Context context, AttributeSet attrs )
constructor.
This is clear when reading the documentation : "Constructor that is called when inflating a view from XML." See: https://developer.android.com/reference/android/view/View.html#View(android.content.Context,%20android.util.AttributeSet)
Hence, never forget basic polymorphism and never forget reading through the documentation. It saves a ton of headache.