Move an image Bitmap from one Fragment to another

0

I have a problem that I still can not find a solution for. I have about an activity two Fragments one takes from a base remora a series of values in which an image is included.

// PHP File

    while ($reg=mysqli_fetch_array($resultado)) {

        $result["nombre"]=$reg['nombre'];
        $result["color"]=$reg['color'];
        $result["texto1"]=$reg['texto1'];
        $result["texto2"]=$reg['texto2'];
        $result["texto3"]=$reg['texto3'];
        $result["texto4"]=$reg['texto4'];
        $result["precio"]=$reg['precio'];
        $result["ancho"]=$reg['ancho'];
        $result["largo"]=$reg['largo'];
        $result["grueso"]=$reg['grueso'];
        $result["informacion"]=$reg['informacion'];
        $result["fotoArticulo"]=base64_encode($reg['fotoArticulo']);


        $json['datos'][]=$result;

    } 

The problem is that the image I recover does not need it in the fragment that recovers it but in the next one. I send the data from the Fragment to the activity that contains them and from the activity I retrieve the data again in the fragment that will show the recovered information.

// Adapter

public void onBindViewHolder(@NonNull final MyViewHolder holder, final int position) {

    holder.id.setText(mDatos.get(position).getNombre());
    holder.color.setText(mDatos.get(position).getColor());



    holder.cardView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            //Recopilacion de datos y transferencia
            Intent intent=new Intent(mContext,ArticulosActivity.class);

            intent.putExtra("nombre",mDatos.get(position).getNombre());
            intent.putExtra("color",mDatos.get(position).getColor());
            intent.putExtra("texto1",mDatos.get(position).getTexto1());
            intent.putExtra("texto2",mDatos.get(position).getTexto2());
            intent.putExtra("texto3",mDatos.get(position).getTexto3());
            intent.putExtra("texto4",mDatos.get(position).getTexto4());
            intent.putExtra("precio",mDatos.get(position).getPrecio());
            intent.putExtra("ancho",mDatos.get(position).getAncho());
            intent.putExtra("largo",mDatos.get(position).getLargo());
            intent.putExtra("grueso",mDatos.get(position).getGrueso());
            intent.putExtra("foto",mDatos.get(position).getFotoArticulo());
            intent.putExtra("informacion",mDatos.get(position).getInformacion());


            //Limpiar todas las actividades extras que se habren
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            mContext.startActivity(intent);


        }
    });

// Activity that retrieves data

static String nombre;
static String color;
static String texto1;
static String texto2;
static String texto3;
static String texto4;
static double precio;
static double ancho;
static double largo;
static double grueso;
static String fotoArticulo;
static String informacion;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_articulos);

    toolbar = (Toolbar)findViewById(R.id.toolbar_activity_articulos);
    setSupportActionBar(toolbar);



    //Recuperacion de datos
    //Con estos dos datos hacer la busqueda php para precios y demas
    Intent intent=getIntent();
    nombre=intent.getExtras().getString("nombre");
    color=intent.getExtras().getString("color");
    texto4=intent.getExtras().getString("texto4");
    ancho=intent.getExtras().getDouble("ancho");
    largo=intent.getExtras().getDouble("largo");
    grueso=intent.getExtras().getDouble("grueso");
    precio=intent.getExtras().getDouble("precio");
    informacion=intent.getExtras().getString("informacion");
    fotoArticulo=intent.getExtras().getString("foto");

// Fragment to which I send from the activity

ArticulosActivity articulosActivity;

public ArticulosDatosFragment() {
    // Required empty public constructor
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment


    View vista=inflater.inflate(R.layout.fragment_articulos_datos, container, false);
    articulosActivity =new ArticulosActivity();

    //Ponemos el RadioGroup a la escucha
    radioGroup=(RadioGroup)vista.findViewById(R.id.txt_radio_group);
    radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            if (checkedId==R.id.txt_radio_eh){
                Toast.makeText(getContext(),"EH Pulsado ",Toast.LENGTH_SHORT).show();
            }
            else if(checkedId==R.id.txt_radio_gh){
                Toast.makeText(getContext(),"GH Pulsado ",Toast.LENGTH_SHORT).show();
            }
        }
    });

    //Ponemos todos los elementos a la escucha
    imageView=(ImageView)vista.findViewById(R.id.txt_imagen_articulo);
    imageView.setImageBitmap(articulosActivity.fotoArticulo);

    informacion=(TextView)vista.findViewById(R.id.txt_articulo_informacion);
    informacion.setText(articulosActivity.informacion);

    texto1=(TextView)vista.findViewById(R.id.txt_text1);
    texto1.setText(articulosActivity.nombre);

    texto2=(TextView)vista.findViewById(R.id.txt_text2);
    texto2.setText(articulosActivity.color);

    texto3=(TextView)vista.findViewById(R.id.txt_text3);
    texto3.setText(articulosActivity.largo+" x "+articulosActivity.ancho+" x "+articulosActivity.grueso);

    texto4=(TextView)vista.findViewById(R.id.txt_text4);
    texto4.setText(articulosActivity.texto4);

    m2=(TextView)vista.findViewById(R.id.txt_precio_metro);
    m2.setText(articulosActivity.precio+"");

// Just as I am doing it as it would be the correct way to recover the image and add it to my ImageView.

Thank you very much in advance

    
asked by Fulano 22.06.2018 в 21:14
source

0 answers