View Not Receiving Clicks
<p>I am creating RelativeLayouts dynamically and adding them to another layout. I want to be able to catch click events from these layouts I'm creating. I've put a test together but cannot seem to get this working. </p>

<p>Here is the Activity which creates the layouts:</p>

<pre><code>public class StatusActivity extends Activity implements OnClickListener
{
    private ArrayList&lt;AvatarItem&gt; _buttonList = new ArrayList&lt;AvatarItem&gt;();
    private TweeterMe _app;
    private Twitter _twitter;
    private RelativeLayout _tweetViewer;
    private TextView _tweetField;
    private ArrayList&lt;Status&gt;_statii;

    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        _app = (TweeterMe)getApplication();
        _twitter = _app.getTwitter();
        setContentView(R.layout.main);

        _tweetViewer = (RelativeLayout) findViewById(R.id.tweet_view);
        _tweetField = (TextView) findViewById(R.id.tweet_text_view);
        _tweetViewer.setVisibility(View.INVISIBLE);

        _tweetViewer.setOnClickListener(new OnClickListener()
        {

            public void onClick(View v)
            {
                _tweetViewer.setVisibility(View.INVISIBLE); 
            }
        });

    }

    @Override
    protected void onResume()
    {
        super.onResume();
        if (!_app.isAuthorized())
        {
            authorize();
        }
        else
        {
            loadTweets();
        }
    }

    private void loadTweets()
    {
        try
        {
            _statii = _twitter.getHomeTimeline();

            RelativeLayout layout = (RelativeLayout)findViewById(R.id.main_view);
            Display display = getWindowManager().getDefaultDisplay();
            Point middle = new Point(display.getWidth() / 2, display.getHeight() / 2);

            for (Status s : _statii)
            {
                AvatarItem ai = new AvatarItem(this, null);
                _buttonList.add(ai);
                ai.setStatus(s);
                ai.setLocation((int)(Math.random() * (display.getWidth() - 100)), (int)(Math.random() * (display.getHeight() - 150)), 500, middle);
                layout.addView(ai);
                ai.setOnClickListener(this);
            }
        }
        catch(TwitterException e)
        {

        }

    }

    private void authorize()
    {
        Intent intent = new Intent(this, AuthorizeActivity.class);
        startActivity(intent);
    }

    public void onClick(View v)
    {
        Log.d("TEST", "NOT WORKING");
    }

}
</code></pre>

<p>Here is the layout I am creating:</p>

<pre><code>public class AvatarItem extends RelativeLayout implements LoadImageAsyncTaskResponder
{

private Status _status;
private ImageButton _avatar;
private AsyncTask&lt;URL, Void, Drawable&gt; _imageLoadTask;
private TranslateAnimation _anim;

public AvatarItem(Context context, AttributeSet attrs)
{
    super(context, attrs);
    setVisibility(View.INVISIBLE);
    _avatar = new ImageButton(getContext());
    addView(_avatar);
}

public void setStatus(Status status)
{
    _status = status;
    final User user = status.getUser();

    if (_imageLoadTask != null)
    {
        _imageLoadTask.cancel(true);
    }

    _imageLoadTask = new LoadImageAsyncTask(this).execute(user.getProfileImageURL());
}

public void setLocation(int x, int y, int duration, Point middle)
{
    _anim = new TranslateAnimation(middle.x, x, middle.y, y);
    _anim.setDuration(duration);
    _anim.setFillEnabled(true);
    _anim.setFillAfter(true);
}

public Status getStatus()
{
    return _status;
}

public ImageButton getButton()
{
    return _avatar;
}

public void imageLoadCancelled()
{
    // Don't care right now
}

public void imageLoaded(Drawable drawable)
{
    setVisibility(View.VISIBLE);
    _avatar.setImageDrawable(drawable);
    startAnimation(_anim);
}

public void imageLoading()
{
    _avatar.setImageDrawable(null);     
}
</code></pre>

<p>}</p>

<p>Here is the layout xml file:</p>

<p></p>

<pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    &gt;
    &lt;RelativeLayout 
        android:id="@+id/main_view"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/&gt;
    &lt;RelativeLayout
        android:id="@+id/tweet_view"
        android:layout_width="fill_parent"
        android:layout_margin="50px"
        android:layout_height="150px"
        android:background="#c5c5c5"
        android:layout_centerInParent="true"&gt;
        &lt;TextView 
            android:id="@+id/tweet_text_view"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"/&gt;
    &lt;/RelativeLayout&gt;
&lt;/RelativeLayout&gt;
</code></pre>

<p>Any thoughts?</p>

<p>Thanks!</p>
