Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ok here is what i'd do:</p> <p>Create a custom control that extends button. I'm not going to do the pretty graphics for you but this will give you the basic idea:</p> <pre><code>import android.content.Context; import android.graphics.Canvas; import android.graphics.Paint; import android.util.AttributeSet; import android.widget.Button; public class CounterButton extends Button{ protected int count=0; protected final Paint myTextPaint = new Paint(); protected final Paint myCirclePaint = new Paint(); public CounterButton(Context context, AttributeSet attrs) { super(context, attrs); this.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.ic_dialog_email)); this.myCirclePaint.setARGB(150, 255, 0, 0); this.myTextPaint.setARGB(150, 255, 255, 255); } @Override protected void onDraw(Canvas canvas) { if(count!=0){ canvas.drawCircle((float) (this.getWidth()*.75), (float) (this.getHeight()*.4), this.getHeight()/5, myCirclePaint); canvas.drawText(Integer.toString(count), (float) (this.getWidth()*.75), (float) (this.getHeight()*.4), this.myTextPaint); } } } </code></pre> <p>Clean up the sizing of your text you draw, the circle positioning (and add a border etc) and you have a custom control. You could further extend it so you could set the background in xml or dynamically and you have a reusable control with a number counter in a circle.</p> <p>then in your code you could do:</p> <pre><code>CounterButton cb=(CounterButton) findViewById(R.id.whateverYouGaveItInXML); cb.count=SomeNewNumber; cb.invalidate; </code></pre> <p>the invalidate will redraw the image with the new value in the circle.</p> <p>I used a button in the event you want to have it clickable easily and all that - but you could just as easily extend view if you are just doing a view.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload