I'm trying to show a PopupWindow from a Fragment but it not works. I've got the error:
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
My code is:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View rootView = inflater.inflate(R.layout.fragment_layout, container, false);
buttton = (Button)rootView.findViewById(R.id.my_button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
LayoutInflater layoutInflater (LayoutInflater)getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popup_window, null, false);
PopupWindow popupWindow = new PopupWindow(popupView, 450, 640);
popupWindow.showAsDropDown(v);
}
});
I can't understand what's the "specified child" from the error. How can I solve this problem? Thanks