Code example for RadioGroup

Methods: getChildCountindexOfChild

0
	} 
 
	@Override 
	public void onDraw(Canvas canvas) {
		RadioGroup radioGroup = (RadioGroup) getParent();
		int index = (radioGroup != null) ? radioGroup.indexOfChild(this) : 0;
 
		final float width = getMeasuredWidth();
		final float height = getMeasuredHeight();
		final float radius = 15.0f;
		final float halfStrokeWidth = 0.8f;
		Path outline = new Path();
 
		if (radioGroup != null && radioGroup.getChildCount() == 1) {
			// Need to draw rounded corners on the left and right. 
 
			// Draw outline, clockwise, starting at top-right corner straight 
			// line segment 
			outline.moveTo(width - halfStrokeWidth, halfStrokeWidth + radius);
			outline.lineTo(width - halfStrokeWidth, height - radius
					- halfStrokeWidth);
			outline.arcTo(new RectF(width - radius - halfStrokeWidth, height
					- radius - halfStrokeWidth, width - halfStrokeWidth, height
					- halfStrokeWidth), 0, 90);
			outline.lineTo(halfStrokeWidth, height - halfStrokeWidth);
			outline.arcTo(new RectF(halfStrokeWidth, height - halfStrokeWidth
					- radius, halfStrokeWidth + radius, height
					- halfStrokeWidth), 90, 90);
			outline.lineTo(halfStrokeWidth, radius + halfStrokeWidth);
			outline.arcTo(new RectF(halfStrokeWidth, halfStrokeWidth, radius,
					radius), 180, 90);
			outline.lineTo(width - radius - halfStrokeWidth, halfStrokeWidth);
			outline.arcTo(new RectF(width - radius - halfStrokeWidth,
					halfStrokeWidth, width - halfStrokeWidth, halfStrokeWidth
							+ radius), 270, 90);
			outline.close();
 
		} else if (index == 0) {
			// Draw outline of left-most button, clockwise, starting at 
			// top-right corner 
			outline.moveTo(width - halfStrokeWidth, halfStrokeWidth);
			outline.lineTo(width - halfStrokeWidth, height - halfStrokeWidth);
			outline.lineTo(radius + halfStrokeWidth, height - halfStrokeWidth);
			outline.arcTo(new RectF(halfStrokeWidth, height - halfStrokeWidth
					- radius, halfStrokeWidth + radius, height
					- halfStrokeWidth), 90, 90);
			outline.lineTo(halfStrokeWidth, radius + halfStrokeWidth);
			outline.arcTo(new RectF(halfStrokeWidth, halfStrokeWidth, radius,
					radius), 180, 90);
			outline.close();
		} else if (radioGroup != null
				&& (index == (radioGroup.getChildCount() - 1))) {
			// Draw outline of right-most button, clockwise, starting at 
			// top-left corner 
			outline.moveTo(halfStrokeWidth, halfStrokeWidth);
			outline.lineTo(width - radius - halfStrokeWidth, halfStrokeWidth);
			outline.arcTo(new RectF(width - radius - halfStrokeWidth,