I have a problem loading RecyclerView images saved on my sql server in an Image field. I have a RecyclerView that is loaded with the data of the name, mail and the photo of the users of the application, already achieve this result. The problem is that said Recycler is heavily loaded by the images it displays from the database. I charge the list with the following code. I would like to know if there is a problem in it or any way to optimize the code so that the images are displayed without slowing down the application to the degree that it stops working. Here the code:
private void LlenarLista() {
try
{
String ConsultaSQL = "Select * From Usuarios ";
Statement Sentencia = SQLClass.conectar().createStatement();
ResultSet Resultado = Sentencia.executeQuery(ConsultaSQL);
Bitmap bm;
while (Resultado.next())
{
if (Resultado.getBytes("Imagen") != null)
{
byte[] b = Resultado.getBytes("Imagen" );
bm = BitmapFactory.decodeByteArray(b,0, b.length);
}
else
{
bm = BitmapFactory.decodeResource(getResources(), R.drawable.user);
}
ListaUsuarios.add(new Usuarios(Resultado.getString("Usuario"), Resultado.getString("Correo"), bm));
}
} catch (SQLException ex)
{
Toast.makeText(getContext(), ex.getMessage(), Toast.LENGTH_SHORT).show();
} catch (Exception EX) {
Toast.makeText(getContext(), EX.getMessage(), Toast.LENGTH_SHORT).show();
}
}
}