Drawing dynamic elements onto a normal xml layout
<p>I've been trying to figure this out for a while now... I need to place marks over top of a seekBar to show the user places that they bookmarked in the past. The data is stored in xml. The problem is making the little ovals appear over the seekBar... It just doesn't work... </p>

<p>Here's my code:</p>

<pre><code>public class seekMark extends View {
    private int     seekLength;     // in pixels 
    private int     seekLeftPad;    // in pixels
    private int     seekBottomPad;  // in pixels
    private int     trackLength;    // in ms
    private float   pxOverMs;       // in px/ms
    ShapeDrawable   lmark;
    private seekMark instance;

    public seekMark(Context context){
        super(context);
        instance = this;
        seekLength = progressBar.getWidth();
        seekLeftPad = progressBar.getPaddingLeft();
        seekBottomPad = progressBar.getBottom();
        trackLength = player.getDuration();
        pxOverMs = pxPerMs();
        lmark = new ShapeDrawable(new OvalShape());
    }

    private float pxPerMs(){
        return ((float) seekLength)/((float) trackLength);
    }

    private int[] markPxList() throws XmlPullParserException, IOException {

        int bmStartTime = 0;
        String bmNames[] = bmNameList(xmlPath);
        int[] bmPos = new int[bmNames.length];

        for(int i=0; i &lt; bmNames.length; i++){
            bmStartTime = getBookmark(xmlPath, bmNames[i]);
            bmPos[i] =  (int) (bmStartTime * pxOverMs);
        }
        return (bmPos);
    }

    public void markPlace() throws XmlPullParserException, IOException {

        int y = seekBottomPad;
        int x = 0;
        int bmPos[] = markPxList();

        for(int i = 0; i &lt; bmPos.length; i++){
            x = bmPos[i] + seekLeftPad;
            lmark = new ShapeDrawable();
            lmark.getPaint().setColor(0xff74AC23);
            lmark.setBounds(x, y, x + 1, y + 1);
            instance.invalidate();
        }

    }
    protected void onDraw(Canvas canvas) {
        lmark.draw(canvas);
    }

}
</code></pre>

<p>It's called from onCreate using this code. I call it using in another thread to avoid the problem where the dimensions of progressBar aren't yet set in onCreate.</p>

<pre><code>Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();

    if (display.getRotation() == 1){   // if landscape

        final Runnable runner = new Runnable() {
            public void run() {
                seekMark seekMarks = new seekMark(context);

                try {
                    seekMarks.markPlace();
                } catch (XmlPullParserException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                // runs in another thread to avoid the problem with calling
                // seekMark directly from onCreate
            }
        };
        handler.postDelayed(runner, 1000);

    }
</code></pre>

<p>The program crashes whenever I try to call seekMark.markPlace()... I'm trying to draw this over top of my layout main.xml.</p>
