I am failing to upload an image by Glide. The specified child already has a parent. You must call removeView () on the child's parent first

1

Good, I'm trying to add an image in the application through Glide or piccasa and it gives me both the same error and I do not know why -

The specified child already has a parent. You must call removeView () on the child's first parent.

I think it fails me because I do not take the context well

It is a class that inherits from Fragment .

Setting v.getContext() , getActivity() or this in with() , gives the same error always

public class Premios extends Fragment {

    public static final String URL = "http://frasesconindirectas.com/wp-content/uploads/2016/10/Im%C3%A1genes-para-Celular-Divertidas-con-Movimiento.jpg";

    ImageView image;

    public Premios() {

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_premios, container);

        image = (ImageView) v.findViewById(R.id.imageView2);

        Glide.with(this).load(URL).into(image);

        return  v;
    }

Let's see if anyone knows why T-T

    
asked by Sergio Alcántara Reyes 30.04.2017 в 22:51
source

1 answer

0

The problem is here:

 View v = inflater.inflate(R.layout.fragment_premios, container);

change the line to:

 View v = inflater.inflate(R.layout.fragment_premios, container, false);

The definition of the third parameter is:

  

A Boolean value that indicates whether the increased design should be appended to   ViewGroup (the second parameter) during the enlargement. (In this   case, it is false because the system is already inserting the design   increased to the container; Passing true would create a group of views   redundant in the final design ).

If you do not add the third parameter, a true value is defined by default, which is causing you to re-inflate the layout by first removing the "current view".

Information about Fragments

    
answered by 04.05.2017 / 23:59
source