Bill L
Bill L

Reputation: 2836

How to destroy a custom view

So I have a custom view I'm implementing, and would like to know how to destroy it when it is clicked. I've tried using onClickListeners, implemented both in and outside of the activity, I've tried calling invalidate() to no avail. At this point I'm stuck with an empty onTouchEvent method and no clue of how to destroy the view when it is clicked.

P.S. By destroy I mean make it disappear from the UI thread.

Upvotes: 5

Views: 13547

Answers (1)

Libin
Libin

Reputation: 17085

You can remove the view from its parent Layout to make it disappear/destroy like this

 parentLayout.removeView(customView);

Or , You can hide the View to disappear and show it back later if required

 customView.setVisibility(View.GONE);

Upvotes: 11

Related Questions