View Page Android - grab list of images within the App and set on the View page.

Asked

Viewed 480 times

0

Guys I have a problem when I need to set my variable in View Page.

I have an Activity that searches the images inside the App and arrow in an Array String, until then it is all correct, I use the code below.

ContextWrapper cw = new ContextWrapper(getApplicationContext());
// path to data/data/yourapp/app_data/imageDir
new_folder = cw.getDir(pasta, Context.MODE_PRIVATE);

if (!new_folder.exists()){
   new_folder.mkdir();
}
// verifica a pasta se tem arquivo //
files = new_folder.listFiles();

if ((files.length > 0)) {
   String[] fileArray = new String[files.length];
   int[] filesResource = new int[files.length];
   for (int i = 0; i < files.length; ++i) {
      fileArray[i] = files[i].getAbsolutePath();
   }
}

Already in my class

public class CustomSwipeAdpter extends PagerAdapter {

I made an example that I saw in several tutorials that this class already has its methods ready... where I have to use an Integer Array, which searches only from drawable. thus:

private int[] image_resources = {R.drawable.image01, R.drawable.image02, R.drawable.image03};

What I really need to do is upload all the images that are inside the App to these variable image_resources, i have been able to do so far is to load the path of the images in an array of strings, already tried to convert the variable Filearray in Integer Array but of error.

If anyone has a solution I thank you... or if you have another example (tutorial, code) already help. Thanks...

  • Where will be used yours array image_resources?

  • will be used here 'imageView.setImageBitmap( decodeSampledBitmapFromResource(Resource, image_resources[position], // here is the problem 1080, 2560));' Before I was using Bitmapfactory.decodeFile but was giving problem...if I had any images with high resolution of the memory burst then I saw this method of the Android site that renders the image. I took this site (http://developer.android.com/intl/pt-br/training/displaying-bitmaps/load-bitmap.html).

1 answer

0


Possible solution would be to use the objeto BitmapDrawable and instill him with his array of String of filepath.

This objeto creates a drawable from a path and decodes the Bitmap.

BitmapDrawable bd = new BitmapDrawable(resource,fileArray[position]);

and in your ImageView

imageView.setImageDrawable(bd);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.