ViewParent
s in general can’t remove views, but ViewGroup
s can. You need to cast your parent to a ViewGroup
(if it is a ViewGroup
) to accomplish what you want.
For example:
View namebar = View.findViewById(R.id.namebar);
((ViewGroup) namebar.getParent()).removeView(namebar);
Note that all Layout
s are ViewGroup
s.