1

I'm working on an app that will have hundreds of different icons (as vector drawables) for users to select from. What is the best way to organize these, save them, and reference them?

  1. Is it best to store the drawable names (R.id.icon) in a database and then call them from there? Building a giant ArrayList doesn't seem right. If so, is there a way to read the names of all drawables in the drawables folder rather than typing them one by one?
  2. Do I really just important 100+ vector images into the drawable folder? Is there anyway to separate them from other drawables in my app?
  • Hundreds of drawables is not much. An arraylist for hundreds of integers or hundreds of strings is nothing. At runtime you can list the files in drawables. There is not much to organise there besides letting for instance the filenames start with the same characters. – blackapps Sep 21 '21 at 21:19
  • @blackapps how do I read all my icon names from drawables? I see Resource.getIdentifier(), but that requires a resource name. All of my svg icons start with "icon..." is there a way I can partial match the string to the resource? – Hank Mountain Sep 21 '21 at 22:32
  • Yes all is possibke as i said. But as you already checked an answer as correct i suppose i dont have to answer anymore. – blackapps Sep 22 '21 at 06:05

2 Answers2

0

you shouldn't put them in database, you have to load them in static int arrays where you can save the position of the icon in a database or in preference. the problem of saving them directly in the database is later when you update the app it will cause you lot of trouble

major dev
  • 26
  • 1
0

I found an answer here: Retrieving all Drawable resources from Resources object

Finding all drawables using Field array and pulling out those with "icons" in the resource name:

    public ArrayList<Integer> loadDrawables() { 
    final Field[] drawables = R.drawable.class.getFields();
    ArrayList<Integer> fieldOfIcons = new ArrayList<Integer>();
    for (Field field : drawables) {
        if (field.getName().contains("icon")) { //Gets all drawables with "icon" in the name and returns resource identifier
            fieldOfIcons.add(getResources().getIdentifier(field.getName(),"drawable", getContext().getPackageName()));
        }
    }
    return fieldOfIcons;