I'm trying to make a simple project of a gallery for android and I have a problem when it comes to getting the images from the server and showing them in my application since it only returns the first registered image and what I'm looking for is to show all the images are registered in the table, I'm almost sure it's because the json is badly formed but I do not know how I should fix it ...
This is the table of my DB:
And this is the part of the code where I "get" the server images
RetrofitInterface retrofitInterface = RetrofitClient.createRetrofit().create(RetrofitInterface.class);
Call<Imagen> call = retrofitInterface.getImagenes();
call.enqueue(new Callback<Imagen>() {
@Override
public void onResponse(Call<Imagen> call, Response<Imagen> response) {
Imagen imagen = response.body();
Imagenes.add(imagen);
AdaptadorImagenes adaptadorImagenes = new AdaptadorImagenes(Imagenes);
recyclerView.setAdapter(adaptadorImagenes);
adaptadorImagenes.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});
}
@Override
public void onFailure(Call<Imagen> call, Throwable t) {
Toast.makeText(getContext(), "ERROR: " + t.getMessage(), Toast.LENGTH_SHORT).show();
}
});
This is the php:
if(mysqli_num_rows($result) > 0){
while($aux = mysqli_fetch_assoc($result)){
$ruta = $aux['rutaImagen'];
$descripcion = $aux['descImage'];
$titulo = $aux['nomImagen'];
$imagen = file_get_contents($ruta);
$encodedImage = base64_encode($imagen);
$respuesta = json_encode(array('imgTitulo'=>$titulo,'imgDescripcion'=>$descripcion,'imgBase64'=>'$encodedImage'));
echo $respuesta;
}
}
And finally this is the answer of the php (I put spaces instead of the base64 image):
{"imgTitulo":"Madoka","imgDescripcion":"Mi preciosa diosa rosada","imgBase64":""}{"imgTitulo":"Mami","imgDescripcion":"Mami Tomoe","imgBase64":""}