Android: draw borders on LinearLayout
<p>I am new to Android. Now I have a problem about drawing borders on LinearLayout. I draw borders by following codes.</p>

<pre><code>   public class Borders{
    int w;
    int h;
    public Borders(int x, int y){
        w = x;
        h = y;
    }

    public void drawBorderInImg(Canvas canvas){
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setStrokeWidth(10);
        paint.setColor(Color.BLACK);
        canvas.drawLine(0, 0, w, 0, paint);
        canvas.drawLine(w, 0, w, h, paint);
        canvas.drawLine(w, h, 0, h, paint);
        canvas.drawLine(0, h, 0, 0, paint);
    }
}
</code></pre>

<p>I create a boolean value and use onclickListener() to control it. By default, the value is false, so there is no border on the screen.</p>

<pre><code>   @Override
        protected void onDraw(Canvas canvas) {
            // TODO Auto-generated method stub
            super.onDraw(canvas);
            // operate.refresh(ShapeData.figureList1);
            Borders borders = new Borders(img01.getWidth(), img01.getHeight());
            if(img01DrawOrNot){
                borders.drawBorderInImg(canvas);
            }
</code></pre>

<p>And then I do </p>

<pre><code>img01.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                if(img01DrawOrNot){
                    img01DrawOrNot = false;
                } else{
                    img01DrawOrNot = true;
                }
            }
        });
</code></pre>

<p>I set <strong>android:clickable=true</strong> in xml. It actually works. But, I need to postInvalidate() it. In fact, I can't refresh it because it contains some random shapes, when I do postInvalidate(), all views will change. How can it change automatically? So when I click, it will appear and when I click again, it will disappear. Could someone help me? Cheers!</p>
