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();
    }
});
Advertisements
Standard

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s