android, Uncategorized

Bubbling OnClick events

Today, I ran into a problem where I needed to bubble up the OnClick event. Inside of a RelativeLayout, I had a TextView which I had to make clickable (so that it could get some animation) because of this, the OnClickevent got swallowed up. To get around this, in the constructor, I create an OnClickListener which would simply call performClick() from the parent.

Here’s how it goes:

final View parent = this;
mTitleView = (TextView) findViewById(R.id.TitleView);
mTitleView.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        parent.performClick();
    }
});
Standard