0
I have an application in which I made an image arrylist, which in this image list has its position, in the method onBindViewHolder
@Override
public void onBindViewHolder(MyAdapter.ViewHolder holder, int position) {
holder.imageView.setImageBitmap(images.get(position));
// clicar nas imagens e setar
holder.imageView.setTag(position);
holder.Baixar.setTag(position);
holder.aplicar.setTag(position);
if (ChecandoseExisteIMG(nomes[position])){
holder.Baixar.setText("Baixado.");
holder.Baixar.setEnabled(false);
}
// botão baixar
holder.Baixar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int clickPosition = (int) v.getTag();
if (haveNetworkConnection()){
downloadFile(ImagensVT[clickPosition],nomes[clickPosition]);
Toast.makeText(context, "Imagem " + (clickPosition+1)+" Baixando!",Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(context, "Não há internet por favor conecte-se!",Toast.LENGTH_SHORT).show();
}
}
}); ...... restante do código }
});
This is an excerpt from my code,this position returns me the position of the images, in all there are 21 images in the list, my problem is that in the if above if(ChecandoseExisteIMG(nomes[position]))
it checks if the image exists in the internal memory if the image is in the memory of the device already downloaded it will set the button as downloaded and not to be clickable anymore, but to get a very boring problem for example downloaded a photo, from position 0
ai worked correcting but I did not download any photos other than this, and in the folder that I created when he downloads the photos only has the photo that I actually downloaded, but I come across this
after in the 7 position list it goes and arrow again being that the image is not downloaded
this is my vector of image names:
String [] nomes = {"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21"};
I wonder how to solve this problem, I do not understand why he is doing this, every 8 numbers he again arrow what is inside if Checandoseexisteimg....
This String vector is just a vector to name the images, in which case it takes the name according to the position to check if the image is in the internal memory..
I already looked if it could be something in the check method and I saw nothing there, the int position of the Onbindviewholder works correctly tb because I tested it with a TOAST that shows how it is being updated, I took the test and it the Toast s from 0 to 20 that shows that the 21 positions are working correctly, who have to help thank you..
If you need anything else I edit the post...
Updated - Methods that check for image
public static boolean ChecandoseExisteIMG(String ImagenNome)
{
Bitmap b = null ;
File file = getImage("/"+ImagenNome+".jpg");
String path = file.getAbsolutePath();
if (path != null)
b = BitmapFactory.decodeFile(path);
if(b == null || b.equals(""))
{
return false ;
}
return true ;
}
// pegando imagem caso tenha
public static File getImage(String imagename) {
File mediaImage = null;
try {
String root = Environment.getExternalStorageDirectory().toString();
File myDir = new File(root);
if (!myDir.exists())
return null;
mediaImage = new File(myDir.getPath() + "/PixelWallpapers"+imagename);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return mediaImage;
}
Viewholder
public class ViewHolder extends RecyclerView.ViewHolder {
ImageView imageView;
Button Baixar;
Button aplicar;
public ViewHolder(View itemView) {
super(itemView);
aplicar=(Button) itemView.findViewById(R.id.aplicar);
Baixar = (Button) itemView.findViewById(R.id.baixarimg);
imageView = (ImageView) itemView.findViewById(R.id.my_imageview);
}
}
Can you add the method code that checks if the image exists? Probably the error is there
– leofontes
I updated @leofontes
– Steve Rogers
You could post your Viewholder?
– Cleiton Oliveira
@Added Cleitonoliveira
– Steve Rogers