In my project I want to add a lot of new images and delete others and I want to get list of all my drawables in res folder in activity. How do I can get it? Or should I use assests folder and get list of images from there?
            Asked
            
        
        
            Active
            
        
            Viewed 849 times
        
    0
            
            
        - 
                    http://stackoverflow.com/questions/2538380/how-to-display-list-of-resource-drawables has the answer to this. – petey Jul 12 '13 at 17:34
- 
                    Ok, how can I cast these fields to Drawable? I'm very newbie in programming. – ext Jul 12 '13 at 17:38
- 
                    There is already a post that describes an strategy to get the images that you need in this folder, based in a prefix and in the method getResources().getIdentifier(...) – Jav_1 Jul 12 '13 at 17:41
2 Answers
0
            
            
        public void searchSDCardForImage() {
        String path = null;
        String uri = MediaStore.Images.Media.DATA;
        String condition = uri + " like '%/GetImageFromThisDirectory/%'";
        String[] projection = { uri, MediaStore.Images.Media.DATE_ADDED,
                MediaStore.Images.Media.SIZE };
        Vector additionalFiles = null;
        try {
            if (additionalFiles == null) {
                additionalFiles = new Vector<String>();
            }
            Cursor cursor = managedQuery(
                    MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection,
                    condition, null, null);
            if (cursor != null) {
                boolean isDataPresent = cursor.moveToFirst();
                if (isDataPresent) {
                    do {
                        path = cursor.getString(cursor.getColumnIndex(uri));
System.out.println("...path..."+path);
additionalFiles.add(path);
            }while(cursor.moveToNext());
                }
            if (cursor != null) {
                cursor.close();
            }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
and also: http://developer.android.com/guide/topics/resources/accessing-resources.html
 
    
    
        Alexander.Iljushkin
        
- 4,519
- 7
- 29
- 46
- 
                    
- 
                    
- 
                    @tyczj, i'm sorry. bad english knowledge... do you want me to delete my answer ? – Alexander.Iljushkin Jul 13 '13 at 11:02
0
            Use this,
Field[] list = R.drawable.class.getFields();
BitmapDrawable[] drawables=new BitmapDrawable[list.length];
for (int i=0;i<list.length;i++){
int id=list[i].getInt(null);
try{
drawables[i]=(BitmapDrawable)getResources().getDrawable(id);
} catch (NotFoundException e) {
// TODO Auto-generated catch block
    e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Hope this helps!!!!!!!!
 
    
    
        Dulanga
        
- 1,326
- 7
- 15
- 
                    
- 
                    Tell me what you actually needs to do. Do you want to do something like converting that to a bitmap. – Dulanga Jul 12 '13 at 17:47
- 
                    
