KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
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(); // find checked text view int childCount = getChildCount(); for (int i = 0; i < childCount; ++i) { View v = getChildAt(i); if (v instanceof CheckedTextView) { _checkbox = (CheckedTextView) v; } } } @Override public boolean isChecked() { return _checkbox != null ? _checkbox.isChecked() : false; } @Override public void setChecked(boolean checked) { if (_checkbox != null) { _checkbox.setChecked(checked); } } @Override public void toggle() { if (_checkbox != null) { _checkbox.toggle(); } } } 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 any duplicate code. How would I go about achieving my goal, seeing that Java does not allow
Tags (comma-separated)
Save Edits
Cancel