android


Glide, Picasso or AsyncTask doesn't work in my RecyclerView


My app has to load some pictures in a RecyclerView. So far I used AsyncTask, Glide and Picasso and neither of them works fine with my code.
Glide doesn't load image on recycled view.
With Picasso, when you go up again, it will go too fast with the las 4 elements
With AsyncTask the items suddenly change images or does not load.
Gif with all 3 http://imgur.com/a/GgIKM
Here is my code.
Edit1: the images are not stored in the device. It's loading from the Internet.
Edit2: If I resize the images with .override(200,200) and remove the .clear() line, this is the result http://imgur.com/a/WhOoV It works but with low quality
Edit3: If I remove the .clear() and in my XML set android:maxWidth="200px" and for height as well, the problem is still there
Edit4: If I change in my item row XML file the android:layout_height="200dp" and android:layout_width="200dp" instead of mach_parent or wrap_content I get thi imgur. com/a/kMkwg
ADAPTER
public class AdaptadorLugares extends RecyclerView.Adapter<AdaptadorLugares.ViewHolder> {
protected Cursor cursor;
protected Lugares lugares; //Lugares a mostrar
protected LayoutInflater inflador; //Crea Layouts con el XML
protected Context contexto; //Lo necesitamos para el inflador
protected View.OnClickListener onClickListener;
AsyncTask<String,Void,Bitmap> task = null;
Bitmap mBitmap;
static boolean primeraVez = true;
ImageView mChart;
public AdaptadorLugares(Context contexto, Lugares lugares, Cursor cursor){
this.cursor = cursor;
this.contexto = contexto;
this.lugares = lugares;
inflador = (LayoutInflater) contexto.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
//Creamos nuestro ViewHolder, con los tipos de elementos a modificar
public static class ViewHolder extends RecyclerView.ViewHolder {
public TextView nombre;// direccion;
public ImageView foto;
public ViewHolder(View itemView) {
super(itemView);
nombre = (TextView) itemView.findViewById(R.id.nombrecito);
foto = (ImageView) itemView.findViewById(R.id.foto);
}
}
// Creamos el ViewHolder con la vista de un elemento sin personalizar
#Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
// Inflamos la vista desde el xml
View v = inflador.inflate(R.layout.elemento_lista, parent,
false);
v.setOnClickListener(onClickListener);
return new ViewHolder(v);
}
// Usando como base el ViewHolder y lo personalizamos
#Override
public void onBindViewHolder(ViewHolder holder, int posicion) {
Lugar lugar = lugares.elemento(posicion+1);
if (lugar != null){
holder.nombre.setText(lugar.get_id() + lugar.getNombre());
//Glide.with(contexto).load(lugar.getImage()).diskCacheStrategy(DiskCacheStrategy.ALL).into(holder.foto);
Picasso.with(contexto).load(lugar.getImage()).into(holder.foto);
//DownLoadImageTask download = new DownLoadImageTask(holder.foto);
//download.execute(lugar.getImage());
}
}
#Override
public void onViewRecycled(final ViewHolder viewHolder) {
super.onViewRecycled(viewHolder);
Glide.clear(viewHolder.foto);
viewHolder.foto.setImageDrawable(null);
}
// Indicamos el nĂºmero de elementos de la lista
#Override
public int getItemCount() {
return lugares.tamanyo();
}
public void setOnItemClickListener(View.OnClickListener onClickListener) {
this.onClickListener = onClickListener;
}
public Cursor getCursor(){
return cursor;
}
public void setCursor(Cursor cursor){
this.cursor = cursor;
}
public Lugar lugarPosicion(int posicion){
cursor.moveToPosition(posicion);
return LugaresBD.extraeLugar(cursor);
}
public int idPosicion(int posicion){
cursor.moveToPosition((posicion));
return cursor.getInt(0);
}
}
DownLoadImageTask
public class DownLoadImageTask extends AsyncTask<String,Void,Bitmap> {
ImageView imageView;
public DownLoadImageTask(ImageView imageView){
this.imageView = imageView;
}
public static Bitmap loadImage(String src)
{
try
{
URL url = new URL(src);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
return myBitmap;
}
catch (IOException e)
{
e.printStackTrace();
return null;
}
}
/*
doInBackground(Params... params)
Override this method to perform a computation on a background thread.
*/
protected Bitmap doInBackground(String...urls){
return loadImage(urls[0]);
}
/*
onPostExecute(Result result)
Runs on the UI thread after doInBackground(Params...).
*/
protected void onPostExecute(Bitmap result){
imageView.setImageBitmap(result);
}
}

Related Links

inflating layer-list of shapes in android
Custom View in Android not Inflating
Displaying list of employees in listview
Tag text in facebook via android application
Using Timer to fetch and display data from SQLite in Listview android
Host name may not be null including http in android
How to share images in android?
Is it possible to show a little of the next fragment on viewpager in Android?
Why show error unexpected namespace prefix xmlns in android?
android send a correct json to php
How to DISPLAY an array of strings on android [closed]
how to move a photo from a folder on sd card to another folder?
Using android-maps-utils with ADT
Upload failed with signing error for new version of an app on Google Play
Air Android - StageWebView and URLLoader cache
ajax doesn't work on galaxy s4 with cordova 3.0

Categories

HOME
url-redirection
google-app-engine
adal
android-studio-2.2
zend-framework
obfuscation
saml-2.0
knitr
tail
character
recordrtc
drop-down-menu
pega
libc
endpoint
nancy
zerobrane
plink
feathersjs
google-picker
pyramid
enterprise-miner
sencha-touch
aggregation
froala
licensing
rpgle
vex
scrollview
cart
deltaspike
sammy.js
joomla2.5
indy10
getlasterror
filesystemwatcher
loading
demo
chef-solo
odoo-website
subclipse
uiimage
jquery-ui-draggable
dotnet-httpclient
arq
aquamacs
android-testing
arules
er-diagram
css-transforms
janus
objectscript
ampps
filenet
node-request
pacemaker
myspace
jtwig
hadoop-partitioning
redis-cluster
yajsw
nio2
inf
forwarding
rpart
uvc
diff3
grouping-sets
post-commit-hook
machine-instruction
human-computer-interface
with-statement
functional-java
renderer
vbe
amslidemenu
conditionaltagsupport
mt4j
inputmismatchexception
tlf
box2d-iphone
workflow-services
update-statement
cloudfiles
mtu
sifr
burndowncharts
filesystemobject
wordprocessingml
entitykey
mathematical-typesetting

Resources

Encrypt Message