As I'm not really sure what this would be called, I could not find any answers using a search engine. I am using polymorphism to dynamicly change the properties of the root element of an activity.
I'm using the following code to get the root element of an activity, usually LinearLayout or RelativeLayout.
ViewGroup layout = (ViewGroup) ((ViewGroup) activity.findViewById(android.R.id.content)).getChildAt(0);
As I want to dynamicly add content in a RelativeLayout to an activity, I would like to test the ViewGroup (layout) if it is a RelativeLayout or LinearLayout.
Is there any way to do this? Without trying to cast to Each of those and catch the exception?
you can use instance of, like this
if (layout instanceof LinearLayout) {
//do some stuff
}