Dori
Dori

Reputation: 18413

Problems overriding methods

I have a subclass of RelativeLayout and I am trying to override some methods (all the addView(...) methods) and I am having a strange problem. When generating the overrides from the Source menu I have the below

@Override
public void addView(View child)
{
    // TODO Auto-generated method stub
    super.addView(child);
}

@Override
public void addView(View child, int index)
{
    // TODO Auto-generated method stub
    super.addView(child, index);
}

@Override
public void addView(View child, int width, int height)
{
    // TODO Auto-generated method stub
    super.addView(child, width, height);
}

@Override
public void addView(View child, LayoutParams params)
{
    // TODO Auto-generated method stub
    super.addView(child, params);
}

@Override
public void addView(View child, int index, LayoutParams params)
{
    // TODO Auto-generated method stub
    super.addView(child, index, params);
} 

But the last two throw compile errors of the type

The method addView(View, int, RelativeLayout.LayoutParams) of type RelativeLayoutWithDataState must override or implement a supertype method

looking at the docs these are all API level 1

http://developer.android.com/reference/android/view/ViewGroup.html#addView(android.view.View, int, android.view.ViewGroup.LayoutParams)

Can anyone shed some light on this, am I being really stupid?!

Thanks!

Upvotes: 2

Views: 936

Answers (1)

Maria Neumayer
Maria Neumayer

Reputation: 3357

You've imported the wrong LayoutParams. It should be ViewGroup.LayoutParams and not RelativeLayout.LayoutParams

That should fix your problem.

Upvotes: 7

Related Questions