My abstract class extended from Activity
class consists of three View
s as described in the following XML snippet:
First change the view in your main layout into a view group (for example, a LinearLayout
). Then you can add views to it. If you add a unique view, it will have exactly the effect you want to achieve.
class OneActivity extends MyActivity {
@Override
protected void initializeContent() {
final ViewGroup viewGroup = (ViewGroup) findViewById(R.id.activity_content);
viewGroup.addView(View.inflate(this, R.layout.some_view, null));
}
}
In your case that should work. If your custom view group contained other views from higher up in the hierarchy, you can clean it before adding your custom view:
viewGroup.removeAllViews();
It works, I do exactly that in most of my projects.
An alternative is to look at the Fragments API, available for latest versions of the SDK.
You can't override class data members in Java, use methods instead