I have this code:
public class CopyOfLinearLayoutEntry extends LinearLayout implements Checkable { private CheckedTextView _checkbox; private Context c; public CopyOfLinearLayoutEntry(Context context) { super(context); this.c = context; setWillNotDraw(false); } public CopyOfLinearLayoutEntry(Context context, AttributeSet attrs) { super(context, attrs); this.c = context; setWillNotDraw(false); } @Override protected void onDraw(Canvas canvas) { Paint strokePaint = new Paint(); strokePaint.setARGB(200, 255, 230, 230); strokePaint.setStyle(Paint.Style.STROKE); strokePaint.setStrokeWidth(12); Rect r = canvas.getClipBounds(); Rect outline = new Rect(1, 1, r.right - 1, r.bottom - 1); canvas.drawLine(r.left, r.top, r.right, r.top, strokePaint); } @Override protected void onFinishInflate() { super.onFinishInflate();
Now I also need a version for RelativeLayout, so I would duplicate the class file and replace "extends LinearLayout" with "extends RelativeLayout". I think that would be bad, because I do not want to duplicate the code.
How can I achieve my goal by seeing that Java does not allow multiple inheritance?
I read something about the composition design template, but I'm not sure how to implement this.
Can someone give me a starting point on how to most elegantly solve this problem?
java android inheritance relativelayout android-linearlayout
cdbeelala89
source share