Android Dynamically Add subviews - Inflaters? General advice needed
<p>I'm from iOS world.  Its quite simple to add a subview in iOS : [mySuperView addSubview:myCustomView].   I can do that anytime anywhere.  Android seems more complicated.</p>

<p>I have a custom view. I simply want to programmatically load as many of my custom views whenever I want.</p>

<p>So I do MyCustomView view = new MyCustomView(this).</p>

<p>What do I do now?</p>

<p>I've been doing Android apps for a year now (business apps), but really want to start getting into the graphics side of Android, but am not sure where to start.  It seems like there are always 10 ways to accomplish a single task in Android.  I have read through 4 Android books and they all give the same basic beginner hand-holding stuff.  (create layout in xml, then find the id in code, etc, etc).</p>

<ol>
<li><p>How do I solve my current problem?</p></li>
<li><p>How can I better learn about layout parameters, canvases &amp; graphics drawing, and more advanced Android topics in general.  </p></li>
</ol>

<p>I want to know the "Why's" behind things. For instance, why is it that I see most people writing their own custom listviews and adapters and not using the provided Android ones, same thing for tab host.  I feel like I'm missing some great obscure gem of knowledge here.</p>

<p>MY CUSTOM VIEW CLASS:</p>

<pre><code>package com.spentaklabs.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;


public class MAView extends View
{
Drawable image;

private float mPosX;
private float mPosY;

private float mLastTouchX;
private float mLastTouchY;

private static final int INVALID_POINTER_ID = -1;

private int mActivePointerId = INVALID_POINTER_ID;

public MAView(Context context)
{
    super(context);
    image = context.getResources().getDrawable(R.drawable.hatshairears0);
    image.setBounds(0, 0, image.getIntrinsicWidth(), image.getIntrinsicHeight());
}

public MAView(Context context, AttributeSet attrs, int defStyle)
{
    super(context,attrs,defStyle);

}

@Override
public void onDraw(Canvas canvas)
{
    canvas.save();
    canvas.translate(mPosX, mPosY);
    image.draw(canvas);
    canvas.restore();
}

@Override
public boolean onTouchEvent(MotionEvent ev)
{
    final int action = ev.getAction();

    switch (action)
    {
        case MotionEvent.ACTION_DOWN:
        {
            final float x = ev.getX();
            final float y = ev.getY();

            mLastTouchX = x;
            mLastTouchY = y;

            mActivePointerId = ev.getPointerId(0);
            break;
        }

        case MotionEvent.ACTION_MOVE:
        {
            final int pointerIndex = ev.findPointerIndex(mActivePointerId);
            final float x = ev.getX(pointerIndex);
            final float y = ev.getY(pointerIndex);
            final float dx = x - mLastTouchX;
            final float dy = y - mLastTouchY;

            mPosX += dx;
            mPosY += dy;

            invalidate();
            break;

        }

        case MotionEvent.ACTION_UP: 
        {
            mActivePointerId = INVALID_POINTER_ID;
            break;
        }

        case MotionEvent.ACTION_CANCEL: 
        {
            mActivePointerId = INVALID_POINTER_ID;
            break;
        }

        case MotionEvent.ACTION_POINTER_UP:
        {
            // Extract the index of the pointer that left the touch sensor
            final int pointerIndex = (action &amp; MotionEvent.ACTION_POINTER_ID_MASK) &gt;&gt; MotionEvent.ACTION_POINTER_ID_SHIFT;
            final int pointerId = ev.getPointerId(pointerIndex);

            if (pointerId == mActivePointerId)
            {
                // This was our active pointer going up. Choose a new
                // active pointer and adjust accordingly.
                final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
                mLastTouchX = ev.getX(newPointerIndex);
                mLastTouchY = ev.getY(newPointerIndex);
                mActivePointerId = ev.getPointerId(newPointerIndex);
            }
            break;
        }
    }
    return true;
}

}
</code></pre>
