View Page Android - pick list of images inside the App and set it on the View page.

0

I am having a problem when I need to set my variable in View Page.

I have an Activity that looks for the images inside the App and arrow in a String Array, until then everything is 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 for drawable. like this:

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

What I really need to do is load all the images that are inside the App for these image_resources variable, I've managed to do so far is loading the path of the images into an Array of strings, convert the FileArray variable into Integer Array but the error.

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

    
asked by anonymous 09.05.2016 / 17:50

1 answer

0

Possible solution would be to use objeto BitmapDrawable and instantiate it with its 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 its ImageView

imageView.setImageDrawable(bd);
    
10.05.2016 / 21:34