I am writing an Android app and just was curious about why we must always type-cast in Android. I understand that we need to be sure of the type so that our code runs proper
findViewById loads resources from a file. It returns some kind of View, but the Java compiler has no way of knowing that it will be a DrawerLayout (because it is defined in a file outside of Java's compilation).
If you need it to be a DrawerLayout in your code, you have to cast it.
That makes sure (at runtime) that it really is such an object (if it is not, you will get a ClassCastException and your program will abort at that point).
The reason you want to cast it as DrawerLayout is that you may want to call methods on the instance that are defined in that class. Sometimes, you may be fine with just the signature of the more general superclass. Then you don't have to cast it.
To be sure, the instance returned by findViewById is a DrawerLayout no matter if you cast it or not. But if you don't cast it, then Java won't let you treat it as a DrawerLayout. That is the point of a type-safe language: Unless the compiler can be sure that an object is of a certain class, it won't let you call methods (or access fields) for that class.