When I create a custom View , where in some cases I need to pass the Context class passed through the constructor for the Activity class to perform some tasks, such as inflating the View directly inside my custom View , I get the following error:
java.lang.ClassCastException: com.android.layoutlib.bridge.android.BridgeContext cannot be cast to android.app.Activity
This is the line throwing this error:
View headerView = ((Activity) context).getLayoutInflater().inflate(R.layout.fragment_history_list_header, null);
It seems that this error only occurs when Eclipse tries to inflate the view that will be displayed in the XML editor (does not occur at run time).
Does anyone know how to fix it?
Thanks in advance.
source share